Documentation ¶
Overview ¶
Source: https://stackoverflow.com/questions/53272536/how-do-i-get-response-statuscode-in-golang-middleware This implementation has some issues as `loggingResponseWriter` doesn't implement multiple interfaces (`CloseNotifier`, Flusher`, etc) that might be used. Better example: https://github.com/urfave/negroni/blob/master/response_writer.go
Index ¶
Constants ¶
View Source
const ( LOGGER MiddlewareType = "logger" RATE_LIMITER = "rate_limiter" BASIC_AUTH = "basic_auth" CACHE_CONTROL = "cache_control" )
View Source
const ( DEFAULT_MAX_REQUESTS = 100 DEFAULT_TIME_FRAME_SECONDS = 20 )
View Source
const (
ASSET_CACHING_DEFAULT_VALUE = "0s"
)
Variables ¶
This section is empty.
Functions ¶
func NewLoggingResponseWriter ¶
func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter
Types ¶
type BasicAuthConfig ¶
type BasicAuthConfig struct { File string `json:"file"` // contains filtered or unexported fields }
func (*BasicAuthConfig) Exec ¶
func (ba *BasicAuthConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type CacheControlConfig ¶
type CacheControlConfig struct { Duration string `json:"duration"` // contains filtered or unexported fields }
func (*CacheControlConfig) Exec ¶
func (cc *CacheControlConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type ClientRequestsCounter ¶
func NewClientRequestsCounter ¶
func NewClientRequestsCounter() *ClientRequestsCounter
func (*ClientRequestsCounter) ReqsInFrame ¶
type LoggerConfig ¶
type LoggerConfig struct { Stream StreamType `json:"stream"` Mode LoggerMode `json:"mode"` // contains filtered or unexported fields }
func (*LoggerConfig) Exec ¶
func (l *LoggerConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type LoggerMode ¶
type LoggerMode string
const ( LoggerModeJSON LoggerMode = "json" LoggerModeText = "text" )
type Middleware ¶
type Middleware interface { Init(context.Context) error Exec(http.HandlerFunc) http.HandlerFunc }
type MiddlewareType ¶
type MiddlewareType string
type RateLimiterConfig ¶
type RateLimiterConfig struct { MaxReqs uint `json:"max_requests"` TimeFrameSecs uint `json:"time_frame_seconds"` // contains filtered or unexported fields }
NOTE: Eventually accept string as TimeFrame, e.g. "15m", "1h"
func (*RateLimiterConfig) Exec ¶
func (rl *RateLimiterConfig) Exec(next http.HandlerFunc) http.HandlerFunc
type StreamType ¶
type StreamType string
const ( StreamTypeStdout StreamType = "stdout" StreamTypeStderr = "stderr" )
Click to show internal directories.
Click to hide internal directories.