middleware

package
v0.0.0-...-bf8f869 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBasicAuthConfig = BasicAuthConfig{
		Realm: "Restricted",
		Validator: func(user, pass string) bool {
			return false
		},
	}
)
View Source
var (
	DefaultCorsConfig = CorsConfig{
		AllowOrigins: []string{"*"},
		AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
		AllowHeaders: []string{"*"},
	}
)
View Source
var (
	DefaultLoggerConfig = LoggerConfig{
		Output:    os.Stdout,
		Formatter: newLoggerFormatter,
	}
)
View Source
var (
	DefaultNoCacheConfig = NoCacheConfig{
		Headers: map[string]string{
			"Cache-Control": "no-cache;no-store",
		},
	}
)

Functions

func BasicAuth

func BasicAuth(valid func(string, string) bool) forest.HandlerFunc

func BasicAuthWithConfig

func BasicAuthWithConfig(config BasicAuthConfig) forest.HandlerFunc

func Cors

func Cors() forest.HandlerFunc

func CorsWithConfig

func CorsWithConfig(config CorsConfig) forest.HandlerFunc

func Logger

func Logger() forest.HandlerFunc

func LoggerWithConfig

func LoggerWithConfig(config LoggerConfig) forest.HandlerFunc

func NoCache

func NoCache() forest.HandlerFunc

func NoCacheWithConfig

func NoCacheWithConfig(config NoCacheConfig) forest.HandlerFunc

func Options

func Options() forest.HandlerFunc

func Recover

func Recover() forest.HandlerFunc

func Skip

func Skip(m forest.HandlerFunc, skips ...Skipper) forest.HandlerFunc

func WrapHandler

func WrapHandler(h http.Handler) forest.HandlerFunc

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	Skipper   Skipper
	Realm     string
	Validator func(string, string) bool
}

type CorsConfig

type CorsConfig struct {
	Skipper          Skipper
	AllowOrigins     []string
	AllowMethods     []string
	AllowHeaders     []string
	AllowCredentials bool
	AllowOriginFunc  func(*http.Request, string) bool
	ExposeHeaders    []string
	MaxAge           time.Duration
}

type LoggerConfig

type LoggerConfig struct {
	Skipper   Skipper
	Output    io.Writer
	Formatter func() LoggerFormatter
}

type LoggerFormatter

type LoggerFormatter interface {
	Reset()
	Format(*http.Request, http.ResponseWriter, int) string
}

type NoCacheConfig

type NoCacheConfig struct {
	Skipper Skipper
	Headers map[string]string
}

type Skipper

type Skipper func(forest.Context) bool

Jump to

Keyboard shortcuts

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