Skip to content

jybp/httpthrottle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpthrottle

GoDoc

Package httpthrottle provides a http.RoundTripper to rate limit HTTP requests.

Usage

package example

import (
    "net/http"
    "github.com/jybp/httpthrottle"
    "golang.org/x/time/rate"
)

func Example() {
    client := &http.Client{
        Transport: httpthrottle.Default(
            // Returns ErrQuotaExceeded if more than 36000 requests occured within an hour.
            httpthrottle.NewQuota(time.Hour, 36000), 
            // Blocks to never exceed 99 requests per second.
            rate.NewLimiter(99, 1), 
        ),
    }
    resp, err := client.Get("https://golang.org/")
    if err == httpthrottle.ErrQuotaExceeded {
        // Handle err.
    }
    if err != nil {
        // Handle err.
    }
    _ = resp // Do something with resp.
}

About

A http.RoundTripper to rate limit HTTP requests.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages