### Advanced Configuration with Multiple Constraints Source: https://context7.com/didip/tollbooth/llms.txt This example showcases advanced rate limiting configuration, combining multiple criteria such as HTTP methods, basic authentication, and API keys. ```APIDOC ## POST /api/write ### Description Applies comprehensive rate limiting to the /api/write endpoint, considering HTTP methods, basic auth, and API keys. ### Method POST, PUT, DELETE ### Endpoint /api/write ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "No request body for this example" } ``` ### Response #### Success Response (200) - **string**: Success message. #### Response Example ```json { "example": "{\"status\": \"success\"}" } ``` ``` -------------------------------- ### Integrate Tollbooth with Go's Standard HTTP ServeMux Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates how to integrate Tollbooth rate limiting with Go's standard `http.ServeMux`. This example shows creating different limiters for distinct routes and applying them using `tollbooth.HTTPMiddleware`. It covers setting custom IP lookups for accurate client identification. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { mux := http.NewServeMux() // Create different limiters for different routes publicLimiter := tollbooth.NewLimiter(10, nil) publicLimiter.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) apiLimiter := tollbooth.NewLimiter(100, nil) apiLimiter.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) apiLimiter.SetHeader("X-API-Key", []string{}) // Apply limiters to routes mux.Handle("/public", tollbooth.HTTPMiddleware(publicLimiter)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Public endpoint")) }))) mux.Handle("/api", tollbooth.HTTPMiddleware(apiLimiter)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("API endpoint")) }))) mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("OK")) }) http.ListenAndServe(":8080", mux) } ``` -------------------------------- ### Limit by HTTP Methods and Basic Auth Users in Go Source: https://context7.com/didip/tollbooth/llms.txt Shows how to configure Tollbooth to limit requests based on specific HTTP methods (e.g., GET, POST) and basic authentication usernames. It also demonstrates how to dynamically remove users from the rate-limiting scope and provides an example of chainable setters for a cleaner configuration. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { lmt := tollbooth.NewLimiter(10, nil) lmt.SetIPLookup(limiter.IPLookup{ Name: "RemoteAddr", IndexFromRight: 0, }) // Only limit GET and POST requests lmt.SetMethods([]string{"GET", "POST"}) // Limit specific basic auth users lmt.SetBasicAuthUsers([]string{"alice", "bob", "charlie"}) // Later, remove a user from rate limiting lmt.RemoveBasicAuthUsers([]string{"charlie"}) // Chainable setters for cleaner configuration lmt.SetMethods([]string{"GET", "POST", "PUT"}). SetBasicAuthUsers([]string{"admin", "poweruser"}). SetMessage("Rate limit exceeded. Please try again later.") http.Handle("/protected", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Protected resource")) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Initialize and Configure Tollbooth Rate Limiter in Go Source: https://github.com/didip/tollbooth/blob/master/README.md Demonstrates how to initialize a Tollbooth rate limiter with default or custom expiration settings. It also shows how to configure IP address lookup, allowed HTTP methods, and basic authentication users. This setup is crucial for defining the rate limiting strategy. ```go import ( "time" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) lmt := tollbooth.NewLimiter(1, nil) // or create a limiter with expirable token buckets // This setting means: // create a 1 request/second limiter and // every token bucket in it will expire 1 hour after it was initially set. lmt = tollbooth.NewLimiter(1, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour}) // New in version >= 8, you must explicitly define how to pick the IP address. // If IP address cannot be found, rate limiter will not be activated. lmt.SetIPLookup(limiter.IPLookup{ // The name of lookup method. // Possible options are: RemoteAddr, X-Forwarded-For, X-Real-IP, CF-Connecting-IP // All other headers are considered unknown and will be ignored. Name: "X-Real-IP", // The index position to pick the ip address from a comma separated list. // The index goes from right to left. // // When there are multiple of the same headers, // we will concat them together in the order of first to last seen. // And then we pick the IP using this index position. IndexFromRight: 0, }) // In version >= 8, lmt.SetIPLookups and lmt.GetIPLookups are removed. // Limit only GET and POST requests. lmt.SetMethods([]string{"GET", "POST"}) // Limit based on basic auth usernames. // You add them on-load, or later as you handle requests. lmt.SetBasicAuthUsers([]string{"bob", "jane", "didip", "vip"}) // You can remove them later as well. lmt.RemoveBasicAuthUsers([]string{"vip"}) // Limit request headers containing certain values. // You add them on-load, or later as you handle requests. lmt.SetHeader("X-Access-Token", []string{"abc123", "xyz098"}) // You can remove all entries at once. lmt.RemoveHeader("X-Access-Token") // Or remove specific ones. lmt.RemoveHeaderEntries("X-Access-Token", []string{"limitless-token"}) // By the way, the setters are chainable. Example: lmt.SetMethods([]string{"GET", "POST"}). SetBasicAuthUsers([]string{"sansa"}). SetBasicAuthUsers([]string{"tyrion"}) ``` -------------------------------- ### Rate Limiting with Context Values Source: https://context7.com/didip/tollbooth/llms.txt This example demonstrates how to use request context values for rate limiting decisions, which is particularly useful when integrating with custom middleware. ```APIDOC ## POST /api ### Description Protects the /api endpoint using rate limiting based on user tier extracted from request context. ### Method GET, POST, PUT, DELETE (applied to the handler) ### Endpoint /api ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "No request body for this example" } ``` ### Response #### Success Response (200) - **string**: User tier information. #### Response Example ```json { "example": "User tier: premium" } ``` ``` -------------------------------- ### Create Basic Rate Limiter in Go Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates how to create a basic rate limiter in Go using Tollbooth, allowing a specified number of requests per second. It also shows how to configure IP address lookup, which is a mandatory step in v8 and later versions. ```go package main import ( "net/http" "time" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func HelloHandler(w http.ResponseWriter, req *http.Request) { w.Write([]byte("Hello, World!")) } func main() { // Create a limiter allowing 1 request per second lmt := tollbooth.NewLimiter(1, nil) // Must explicitly define IP lookup method (v8+ requirement) lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) // Apply middleware to handler http.Handle("/", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(HelloHandler))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Advanced Rate Limiter Configuration in Go Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates comprehensive rate limiting configuration with multiple constraints, custom messages, and expiration settings. It uses method chaining for a fluent API and allows for a custom handler when rate limits are reached. Dependencies include `net/http`, `time`, and the Tollbooth library. ```go package main import ( "net/http" "time" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { // Create limiter with 50 requests per second lmt := tollbooth.NewLimiter(50.5, &limiter.ExpirableOptions{ DefaultExpirationTTL: 2 * time.Hour, }) // Configure IP lookup lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Forwarded-For", IndexFromRight: 0, }) // Comprehensive configuration using method chaining lmt.SetMethods([]string{"POST", "PUT", "DELETE"}). SetBasicAuthUsers([]string{"admin", "operator"}). SetHeader("X-API-Key", []string{"premium-key-1", "premium-key-2"}). SetMessage(`{"error": "Rate limit exceeded", "limit": 50, "window": "1s"}`). SetMessageContentType("application/json"). SetStatusCode(429). SetIgnoreURL(false). SetTokenBucketExpirationTTL(30 * time.Minute). SetBasicAuthExpirationTTL(1 * time.Hour). SetHeaderEntryExpirationTTL(45 * time.Minute) // Custom rate limit reached handler lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { // Log to monitoring system // Send metrics // Trigger alerts if needed }) http.Handle("/api/write", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"status": "success"}`)) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Configure and Use Tollbooth Rate Limiter Middleware (Go) Source: https://github.com/didip/tollbooth/blob/master/README.md This Go code demonstrates how to set up and use the Tollbooth rate limiter. It creates a limiter, explicitly defines how to look up the client's IP address using the 'X-Real-IP' header, and integrates it as middleware for an HTTP handler. It highlights the v8.x.x API for IP lookup and HTTPMiddleware. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8/limiter" ) func HelloHandler(w http.ResponseWriter, req *http.Request) { w.Write([]byte("Hello, World!")) } func main() { // Create a request limiter per handler. lmt := tollbooth.NewLimiter(1, nil) // New in version >= 8, you must explicitly define how to pick the IP address. lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) // New in version >= 8, HTTPMiddleware is a standard router compatible alternative to the previously used LimitFuncHandler. http.Handle("/", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(HelloHandler))) // Old syntax: // http.Handle("/", tollbooth.LimitFuncHandler(lmt, HelloHandler)) http.ListenAndServe(":12345", nil) } ``` -------------------------------- ### Wrap http.Handler with Tollbooth's LimitHandler Source: https://context7.com/didip/tollbooth/llms.txt Illustrates how to wrap existing `http.Handler` implementations with Tollbooth's rate limiting middleware using `tollbooth.LimitHandler`. This allows applying rate limits to custom handlers or standard library handlers like `http.FileServer`. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) type CustomHandler struct { message string } func (h *CustomHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Write([]byte(h.message)) } func main() { lmt := tollbooth.NewLimiter(20, nil) lmt.SetIPLookup(limiter.IPLookup{ Name: "RemoteAddr", IndexFromRight: 0, }) // Wrap custom handler customHandler := &CustomHandler{message: "Custom handler response"} limitedHandler := tollbooth.LimitHandler(lmt, customHandler) // Wrap standard file server fileServer := http.FileServer(http.Dir("./static")) limitedFileServer := tollbooth.LimitHandler(lmt, fileServer) http.Handle("/custom", limitedHandler) http.Handle("/static/", http.StripPrefix("/static/", limitedFileServer)) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Limit by Custom Headers with Tollbooth Go Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates how to apply rate limits based on specific HTTP header values using the Tollbooth library in Go. This is useful for API key or token-based limiting. It shows setting, adding, and removing header entries for rate limiting. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { lmt := tollbooth.NewLimiter(100, nil) lmt.SetIPLookup(limiter.IPLookup{ Name: "CF-Connecting-IP", // Cloudflare header IndexFromRight: 0, }) // Rate limit by API key header lmt.SetHeader("X-API-Key", []string{"key123", "key456"}) // Rate limit by Authorization header (any value) lmt.SetHeader("Authorization", []string{}) // Later, add more keys dynamically lmt.SetHeader("X-API-Key", []string{"key789"}) // Remove specific header entries lmt.RemoveHeaderEntries("X-API-Key", []string{"key456"}) // Remove all entries for a header lmt.RemoveHeader("Authorization") http.Handle("/api/data", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"data": "response"}`)) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Rate Limiting with Context Values in Go Source: https://context7.com/didip/tollbooth/llms.txt Implements rate limiting based on custom context values extracted from incoming requests. This is useful for applying different limits to different user tiers or authenticated users. It requires the `context` and `net/http` packages, along with the Tollbooth library. ```go package main import ( "context" "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) type contextKey string const ( userTierKey contextKey = "user_tier" ) func AuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Simulate authentication and tier extraction tier := r.Header.Get("X-User-Tier") if tier == "" { tier = "free" } ctx := context.WithValue(r.Context(), userTierKey, tier) next.ServeHTTP(w, r.WithContext(ctx)) }) } func main() { lmt := tollbooth.NewLimiter(10, nil) lmt.SetIPLookup(limiter.IPLookup{ Name: "RemoteAddr", IndexFromRight: 0, }) // Rate limit based on context values lmt.SetContextValues(map[string][]string{ "user_tier": {"premium", "enterprise"}, }) // Add or remove context value entries dynamically lmt.SetContextValue("user_tier", []string{"premium"}) lmt.RemoveContextValuesEntries("user_tier", []string{"enterprise"}) handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { tier := r.Context().Value(userTierKey) w.Write([]byte("User tier: " + tier.(string))) }) http.Handle("/api", AuthMiddleware(tollbooth.HTTPMiddleware(lmt)(handler))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Check Remaining Tokens with LimitByKeysAndReturn in Go Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates how to use Tollbooth's LimitByKeysAndReturn function in Go to check the rate limit status and retrieve the number of remaining tokens for a given key. This allows for more informative responses to clients regarding their rate limit status. ```go package main import ( "encoding/json" "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) type RateLimitResponse struct { Success bool `json:"success"` Message string `json:"message"` TokensRemaining int `json:"tokens_remaining"` } func RateLimitWithTokensHandler(lmt *limiter.Limiter) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { userID := r.Header.Get("X-User-ID") keys := []string{userID} // Get both error and remaining tokens httpError, tokensLeft := tollbooth.LimitByKeysAndReturn(lmt, keys) w.Header().Set("Content-Type", "application/json") if httpError != nil { resp := RateLimitResponse{ Success: false, Message: httpError.Message, TokensRemaining: tokensLeft, } w.WriteHeader(httpError.StatusCode) json.NewEncoder(w).Encode(resp) return } // Include tokens remaining in success response resp := RateLimitResponse{ Success: true, Message: "Request successful", TokensRemaining: tokensLeft, } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(resp) } } func main() { lmt := tollbooth.NewLimiter(100, nil) http.HandleFunc("/api/user-action", RateLimitWithTokensHandler(lmt)) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Custom Rate Limiting Logic with LimitByKeys in Go Source: https://context7.com/didip/tollbooth/llms.txt Implements custom rate limiting logic by composing your own keys for granular control using Tollbooth's LimitByKeys function in Go. This allows for rate limiting based on combinations of request attributes, like tenant ID and endpoint. ```go package main import ( "fmt" "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func CustomRateLimitHandler(lmt *limiter.Limiter) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // Build custom key based on tenant ID and endpoint tenantID := r.Header.Get("X-Tenant-ID") endpoint := r.URL.Path // Create composite key keys := []string{tenantID, endpoint} // Check rate limit httpError := tollbooth.LimitByKeys(lmt, keys) if httpError != nil { w.Header().Set("Content-Type", lmt.GetMessageContentType()) w.WriteHeader(httpError.StatusCode) w.Write([]byte(httpError.Message)) return } // Process request w.Write([]byte(fmt.Sprintf("Request processed for tenant: %s", tenantID))) } } func main() { lmt := tollbooth.NewLimiter(50, nil) // For custom key logic, you may want to ignore URL in default limiting lmt.SetIgnoreURL(true) http.HandleFunc("/tenant-api", CustomRateLimitHandler(lmt)) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Configure Tollbooth IP Lookup Methods Source: https://context7.com/didip/tollbooth/llms.txt Demonstrates various methods for configuring client IP address lookup in Tollbooth. This includes using `RemoteAddr`, `X-Forwarded-For`, `X-Real-IP`, and `CF-Connecting-IP` headers, with options to specify the index for headers that may contain multiple IPs. ```go package main import ( "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { // Method 1: Use RemoteAddr directly lmt1 := tollbooth.NewLimiter(10, nil) lmt1.SetIPLookup(limiter.IPLookup{ Name: "RemoteAddr", IndexFromRight: 0, }) // Method 2: Use X-Forwarded-For (common behind proxies) lmt2 := tollbooth.NewLimiter(10, nil) lmt2.SetIPLookup(limiter.IPLookup{ Name: "X-Forwarded-For", IndexFromRight: 0, // Rightmost IP (closest proxy) }) // Method 3: Use X-Real-IP (nginx) lmt3 := tollbooth.NewLimiter(10, nil) lmt3.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) // Method 4: Use CF-Connecting-IP (Cloudflare) lmt4 := tollbooth.NewLimiter(10, nil) lmt4.SetIPLookup(limiter.IPLookup{ Name: "CF-Connecting-IP", IndexFromRight: 0, }) // X-Forwarded-For with index from right // If header is "1.1.1.1, 2.2.2.2, 3.3.3.3" // IndexFromRight: 0 returns "3.3.3.3" // IndexFromRight: 1 returns "2.2.2.2" // IndexFromRight: 2 returns "1.1.1.1" lmtMultiProxy := tollbooth.NewLimiter(10, nil) lmtMultiProxy.SetIPLookup(limiter.IPLookup{ Name: "X-Forwarded-For", IndexFromRight: 1, // Get second IP from right }) http.Handle("/direct", tollbooth.HTTPMiddleware(lmt1)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Direct connection")) }))) http.Handle("/proxied", tollbooth.HTTPMiddleware(lmt2)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Behind proxy")) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Create Rate Limiter with Expirable Token Buckets in Go Source: https://context7.com/didip/tollbooth/llms.txt Illustrates the creation of a Tollbooth rate limiter with expirable token buckets. This configuration ensures that token buckets are automatically cleaned up after a specified duration, preventing memory leaks in long-running applications. It also covers custom expiration settings for different limiter components. ```go package main import ( "net/http" "time" "github.com/didip/tollbooth/v8" "github.com/didipip/tollbooth/v8/limiter" ) func main() { // Create limiter with 5 requests/second, token buckets expire after 1 hour lmt := tollbooth.NewLimiter(5, &limiter.ExpirableOptions{ DefaultExpirationTTL: time.Hour, }) lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Forwarded-For", IndexFromRight: 0, // Pick rightmost IP from X-Forwarded-For }) // Custom expiration for different components lmt.SetTokenBucketExpirationTTL(30 * time.Minute) lmt.SetBasicAuthExpirationTTL(2 * time.Hour) lmt.SetHeaderEntryExpirationTTL(45 * time.Minute) http.Handle("/api", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("API Response")) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Custom Limit Reached Behavior with Tollbooth Go Source: https://context7.com/didip/tollbooth/llms.txt Shows how to configure custom messages, status codes, and callback functions when rate limits are exceeded using Tollbooth in Go. This allows for tailored responses and actions when a client hits a rate limit. ```go package main import ( "fmt" "log" "net/http" "github.com/didip/tollbooth/v8" "github.com/didip/tollbooth/v8/limiter" ) func main() { lmt := tollbooth.NewLimiter(2, nil) lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Real-IP", IndexFromRight: 0, }) // Custom error message lmt.SetMessage(`{"error": "Too many requests", "retry_after": 1}`) // Custom content type lmt.SetMessageContentType("application/json; charset=utf-8") // Custom status code (default is 429) lmt.SetStatusCode(http.StatusTooManyRequests) // Custom callback when limit is reached lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { log.Printf("Rate limit exceeded for IP: %s, Path: %s", r.RemoteAddr, r.URL.Path) // Could send metrics, alerts, or custom logging here }) http.Handle("/limited", tollbooth.HTTPMiddleware(lmt)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Success")) }))) http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Customize Rejection Message and Handler in Go Source: https://github.com/didip/tollbooth/blob/master/README.md Allows customization of the response when a rate limit is reached. This includes setting a custom rejection message, content type, and a callback function (`OnLimitReached`) to execute custom logic upon rejection. It also reiterates the importance of configuring IP lookup. ```go import ( "fmt" "net/http" "github.com/didip/tollbooth/v8/limiter" ) lmt := tollbooth.NewLimiter(1, nil) // New in version >= 8, you must explicitly define how to pick the IP address. lmt.SetIPLookup(limiter.IPLookup{ Name: "X-Forwarded-For", IndexFromRight: 0, }) // Set a custom message. lmt.SetMessage("You have reached maximum request limit.") // Set a custom content-type. lmt.SetMessageContentType("text/plain; charset=utf-8") // Set a custom function for rejection. lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { fmt.Println("A request was rejected") }) ``` -------------------------------- ### Set Custom Expiration TTL for Tollbooth Entries in Go Source: https://github.com/didip/tollbooth/blob/master/README.md Configures custom expiration times (TTL) for token buckets, basic auth users, and header entries within the Tollbooth rate limiter. This helps manage memory usage by automatically removing old entries. The TTL is set using `time.Duration`. ```go import "time" lmt := tollbooth.NewLimiter(1, nil) // Set a custom expiration TTL for token bucket. lmt.SetTokenBucketExpirationTTL(time.Hour) // Set a custom expiration TTL for basic auth users. lmt.SetBasicAuthExpirationTTL(time.Hour) // Set a custom expiration TTL for header entries. lmt.SetHeaderEntryExpirationTTL(time.Hour) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.