Documentation ¶
Index ¶
- Constants
- Variables
- func GzipMiddleware(next http.Handler) http.Handler
- func NewLoggingMiddleware(out io.Writer) func(http.Handler) http.Handler
- func NewOmitHeadersMiddleware(headersToOmit []string) func(http.Handler) http.Handler
- func NewRateLimitMiddleware(limits []string) (func(http.Handler) http.Handler, error)
- func NewRequestSizeLimitMiddleware(maxSize uint64) func(http.Handler) http.Handler
- func NewTimeoutMiddleware(timeout time.Duration) func(next http.Handler) http.Handler
- type CachedResponse
- type HandlerWithMiddleware
- type LimitConfig
- type Middleware
- func NewAddHeadersMiddleware(headers map[string]string) Middleware
- func NewCacheMiddleware() Middleware
- func NewMinifyMiddleware(config MinifyConfig) Middleware
- func NewOpenAPIValidationMiddleware(specPath string) (Middleware, error)
- func NewOpenTelemetryMiddleware(ctx context.Context, config OTELConfig) (Middleware, error)
- type MinifyConfig
- type OTELConfig
- type RateLimiter
- type ResponseRecorder
- func (rw *ResponseRecorder) Header() http.Header
- func (rw *ResponseRecorder) Result() *http.Response
- func (rw *ResponseRecorder) Write(buf []byte) (int, error)
- func (rw *ResponseRecorder) WriteHeader(code int)
- func (rr *ResponseRecorder) WriteHeadersTo(rw http.ResponseWriter)
- func (rw *ResponseRecorder) WriteString(str string) (int, error)
- func (rr *ResponseRecorder) WriteTo(rw http.ResponseWriter)
Constants ¶
const CLEANUP_CACHE_INTERVAL = time.Minute * 10
const DEFAULT_CACHE_TTL = time.Minute * 1
const DefaultRemoteAddr = "1.2.3.4"
DefaultRemoteAddr is the default remote address to return in RemoteAddr if an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
Variables ¶
var ErrZoneNotSupported = errors.New("rate limit zone is not supported")
var SupportedZones = []string{"ip"}
Functions ¶
func GzipMiddleware ¶
GzipMiddleware compresses the response using gzip if the client supports it
func NewLoggingMiddleware ¶
Logging middleware log the request / response with the log style of nginx
func NewOmitHeadersMiddleware ¶
OmitHeaders middleware removes specified headers from the response to enhance security.
func NewRateLimitMiddleware ¶
func NewRequestSizeLimitMiddleware ¶
NewRequestSizeLimitMiddleware limits the size of the request body to the specified limit in bytes.
func NewTimeoutMiddleware ¶
NewTimeoutMiddleware returns an HTTP handler that wraps the provided handler with a timeout. If the processing takes longer than the specified timeout, it returns a 503 Service Unavailable error.
Types ¶
type CachedResponse ¶
type CachedResponse struct {
// contains filtered or unexported fields
}
type HandlerWithMiddleware ¶
type HandlerWithMiddleware struct {
// contains filtered or unexported fields
}
func NewHandlerWithMiddleware ¶
func NewHandlerWithMiddleware(handler http.Handler) *HandlerWithMiddleware
func (*HandlerWithMiddleware) Add ¶
func (h *HandlerWithMiddleware) Add(middleware Middleware)
func (*HandlerWithMiddleware) ServeHTTP ¶
func (h *HandlerWithMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type LimitConfig ¶
func ParseLimitConfig ¶
func ParseLimitConfig(config string) (LimitConfig, error)
type Middleware ¶
func NewAddHeadersMiddleware ¶
func NewAddHeadersMiddleware(headers map[string]string) Middleware
func NewCacheMiddleware ¶
func NewCacheMiddleware() Middleware
func NewMinifyMiddleware ¶
func NewMinifyMiddleware(config MinifyConfig) Middleware
func NewOpenAPIValidationMiddleware ¶
func NewOpenAPIValidationMiddleware(specPath string) (Middleware, error)
func NewOpenTelemetryMiddleware ¶
func NewOpenTelemetryMiddleware(ctx context.Context, config OTELConfig) (Middleware, error)
type MinifyConfig ¶
type OTELConfig ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter() *RateLimiter
type ResponseRecorder ¶
type ResponseRecorder struct { // Code is the HTTP response code set by WriteHeader. // // Note that if a Handler never calls WriteHeader or Write, // this might end up being 0, rather than the implicit // http.StatusOK. To get the implicit value, use the Result // method. Code int // HeaderMap contains the headers explicitly set by the Handler. // It is an internal detail. // // Deprecated: HeaderMap exists for historical compatibility // and should not be used. To access the headers returned by a handler, // use the Response.Header map as returned by the Result method. HeaderMap http.Header // Body is the buffer to which the Handler's Write calls are sent. // If nil, the Writes are silently discarded. Body *bytes.Buffer // Flushed is whether the Handler called Flush. Flushed bool // contains filtered or unexported fields }
ResponseRecorder is an implementation of http.ResponseWriter.
func NewRecorder ¶
func NewRecorder() *ResponseRecorder
NewRecorder returns an initialized ResponseRecorder.
func (*ResponseRecorder) Header ¶
func (rw *ResponseRecorder) Header() http.Header
Header implements http.ResponseWriter. It returns the response headers to mutate within a handler.
func (*ResponseRecorder) Result ¶
func (rw *ResponseRecorder) Result() *http.Response
Result returns the response generated by the handler.
The returned Response will have at least its StatusCode, Header, Body, and optionally Trailer populated. More fields may be populated in the future, so callers should not DeepEqual the result in tests.
The Response.Header is a snapshot of the headers at the time of the first write call, or at the time of this call, if the handler never did a write.
The Response.Body is guaranteed to be non-nil and Body.Read call is guaranteed to not return any error other than io.EOF.
Result must only be called after the handler has finished running.
func (*ResponseRecorder) Write ¶
func (rw *ResponseRecorder) Write(buf []byte) (int, error)
Write implements http.ResponseWriter. The data in buf is written to rw.Body, if not nil.
func (*ResponseRecorder) WriteHeader ¶
func (rw *ResponseRecorder) WriteHeader(code int)
WriteHeader implements http.ResponseWriter.
func (*ResponseRecorder) WriteHeadersTo ¶
func (rr *ResponseRecorder) WriteHeadersTo(rw http.ResponseWriter)
func (*ResponseRecorder) WriteString ¶
func (rw *ResponseRecorder) WriteString(str string) (int, error)
WriteString implements io.StringWriter. The data in str is written to rw.Body, if not nil.
func (*ResponseRecorder) WriteTo ¶
func (rr *ResponseRecorder) WriteTo(rw http.ResponseWriter)