middleware

package
v0.0.0-...-fd23a95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 13 Imported by: 0

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 (*BasicAuthConfig) Init

func (ba *BasicAuthConfig) Init(ctx context.Context) error

type CacheControlConfig

type CacheControlConfig struct {
	Duration string `json:"duration"`
	// contains filtered or unexported fields
}

func (*CacheControlConfig) Exec

func (*CacheControlConfig) Init

func (cc *CacheControlConfig) Init(ctx context.Context) error

type ClientRequestsCounter

type ClientRequestsCounter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClientRequestsCounter

func NewClientRequestsCounter() *ClientRequestsCounter

func (*ClientRequestsCounter) ReqsInFrame

func (c *ClientRequestsCounter) ReqsInFrame(reqTime time.Time, timeframe time.Duration) int

type LoggerConfig

type LoggerConfig struct {
	Stream StreamType `json:"stream"`
	Mode   LoggerMode `json:"mode"`
	// contains filtered or unexported fields
}

func (*LoggerConfig) Exec

func (*LoggerConfig) Init

func (l *LoggerConfig) Init(ctx context.Context) error

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 (*RateLimiterConfig) Init

func (rl *RateLimiterConfig) Init(ctx context.Context) error

type StreamType

type StreamType string
const (
	StreamTypeStdout StreamType = "stdout"
	StreamTypeStderr            = "stderr"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL