package broker import ( "context" "local/truckstop/config" "net/http" "strings" "golang.org/x/time/rate" ) // once per minute var authlimiter = rate.NewLimiter(rate.Limit(1.0/60.0), 1) // thrice per minute var limiter = rate.NewLimiter(rate.Limit(1.0/20.0), 1) type Broker interface { Search([]config.State) ([]Job, error) } func do(r *http.Request) (*http.Response, error) { limiter.Wait(context.Background()) if strings.Contains(strings.ToLower(r.URL.Path), "login") { authlimiter.Wait(context.Background()) } return http.DefaultClient.Do(r) }