Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = Config{ Skipper: middleware.DefaultSkipper, MaxConcurrent: 100, WaitTimeout: 10 * time.Second, }
DefaultConfig is the default configuration for the steady middleware.
Functions ¶
func New ¶
func New(config Config) echo.MiddlewareFunc
New returns a steady middleware that limits concurrent requests.
Example ¶
package main
import (
"net/http"
"time"
"github.com/its-ernest/http-keystone/steady"
"github.com/labstack/echo/v5"
)
func main() {
e := echo.New()
// Configure the steady middleware with a maximum of 10 concurrent requests
// and a 5-second wait timeout for a slot.
config := steady.Config{
MaxConcurrent: 10,
WaitTimeout: 5 * time.Second,
}
// Add the middleware to the Echo instance
e.Use(steady.New(config))
e.GET("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Start(":8080")
}
Output:
Types ¶
type Config ¶
type Config struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// MaxConcurrent is the maximum number of concurrent requests allowed.
// Default is 100.
MaxConcurrent int
// WaitTimeout is the maximum time a request will wait for a processing slot.
// Default is 10 seconds.
WaitTimeout time.Duration
// ErrorHandler is called when a request exceeds the limit.
// Default returns 503 Service Unavailable with Retry-After header.
ErrorHandler func(c *echo.Context) error
}
Config defines the configuration for the steady middleware.
Click to show internal directories.
Click to hide internal directories.