Documentation
¶
Index ¶
- Constants
- func Bind(mid Middleware, route http.HandlerFunc) http.HandlerFunc
- func Compress(next http.Handler) http.Handler
- func ContextTimeout(duration time.Duration) func(http.Handler) http.Handler
- func IDFromContext(ctx context.Context) string
- func Log(next http.Handler) http.Handler
- func Recover(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- type Cache
- type Item
- type Middleware
- type StatusHTTP
- type Storage
Constants ¶
const RequestIDKey ctxKey = "request_id"
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
func Bind(mid Middleware, route http.HandlerFunc) http.HandlerFunc
Bind applies the middleware to the route handler. This function takes a Middleware and an http.HandlerFunc (the route handler) and returns a new http.HandlerFunc that incorporates the middleware logic.
func ContextTimeout ¶
ContextTimeout is a middleware that sets a timeout on the request context. It will be useful for long tasks such as IO or long queries at database. Strictly use with context cancellation in your handlers! Otherwise the middleware will be useless.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache struct for caching strings in memory
func (*Cache) CacheResponse ¶
CacheResponse middleware
type Middleware ¶
func Limit ¶
func Limit(requestsPerSecond rate.Limit, maxRequests int) Middleware
Limit middleware requestsPerSecond sets how many requests are allowed per second. maxRequests sets the maximum burst size.
func Middlewares ¶
func Middlewares(middlewares ...Middleware) Middleware
Middlewares chains multiple middleware functions together. in order of execution
type StatusHTTP ¶
type StatusHTTP struct {
http.ResponseWriter
StatusCode int
// contains filtered or unexported fields
}
StatusHTTP custom struct for show response status code in log middleware
func NewStatusHTTP ¶
func NewStatusHTTP(w http.ResponseWriter) *StatusHTTP
NewStatusHTTP function init new StatusHTTP
func (*StatusHTTP) WriteHeader ¶
func (sr *StatusHTTP) WriteHeader(statusCode int)
WriteHeader method wrties status code in http header
type Storage ¶
type Storage interface {
// Get retrieves the cached content for the given key.
Get(key string) ([]byte, string)
// Set stores the content in the cache with the specified key and duration.
Set(key string, content []byte, contentType string, duration time.Duration)
}
Storage interface for cache middleware implementation