func (c *ProxyController) AddLocationConnLimit(w http.ResponseWriter, r *http.Request, params map[string]string) (interface{}, error) { hostname := params["hostname"] locationId := params["location"] id, err := api.GetStringField(r, "id") if err != nil { return nil, err } connections, err := api.GetIntField(r, "connections") if err != nil { return nil, err } variable, err := api.GetStringField(r, "variable") if err != nil { return nil, err } connLimit, err := backend.NewConnLimit(connections, variable) if err != nil { return nil, api.GenericAPIError{Reason: fmt.Sprintf("%s", err)} } if err := c.backend.AddLocationConnLimit(hostname, locationId, id, connLimit); err != nil { return nil, api.GenericAPIError{Reason: fmt.Sprintf("%s", err)} } return api.Response{"message": "Rate added"}, nil }
func (c *ProxyController) UpdateLocationRateLimit(w http.ResponseWriter, r *http.Request, params map[string]string) (interface{}, error) { hostname := params["hostname"] locationId := params["location"] id := params["id"] requests, err := api.GetIntField(r, "requests") if err != nil { return nil, err } seconds, err := api.GetIntField(r, "seconds") if err != nil { return nil, err } burst, err := api.GetIntField(r, "burst") if err != nil { return nil, err } variable, err := api.GetStringField(r, "variable") if err != nil { return nil, err } rateLimit, err := backend.NewRateLimit(requests, variable, burst, seconds) if err != nil { return nil, api.GenericAPIError{Reason: fmt.Sprintf("%s", err)} } if err := c.backend.UpdateLocationRateLimit(hostname, locationId, id, rateLimit); err != nil { return nil, api.GenericAPIError{Reason: fmt.Sprintf("%s", err)} } return api.Response{"message": "Rate added"}, nil }