Exemple #1
0
// Returns vulcan library compatible middleware
func (c *ConnLimit) NewHandler(next http.Handler) (http.Handler, error) {
	extract, err := utils.NewExtractor(c.Variable)
	if err != nil {
		return nil, err
	}
	return connlimit.New(next, extract, c.Connections)
}
Exemple #2
0
func NewConnLimit(connections int64, variable string) (*ConnLimit, error) {
	if _, err := utils.NewExtractor(variable); err != nil {
		return nil, err
	}
	if connections < 0 {
		return nil, fmt.Errorf("connections should be > 0, got %d", connections)
	}
	return &ConnLimit{
		Connections: connections,
		Variable:    variable,
	}, nil
}