middleware

package
v0.0.0-...-4471eec Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2015 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BestCompression    = gzip.BestCompression
	BestSpeed          = gzip.BestSpeed
	DefaultCompression = gzip.DefaultCompression
	NoCompression      = gzip.NoCompression
)

These compression constants are copied from the compress/gzip package.

View Source
const (
	RequestIDHeaderKey = "X-Request-Id"
	ServerHeaderValue  = "MessageDB"
)
View Source
const ApiTokenHeaderKey = "X-MessageDB-Api-Token"
View Source
const ContentTypeHeaderKey = "Content-Type"

Variables

This section is empty.

Functions

func ApiTokenMiddleware

func ApiTokenMiddleware() gin.HandlerFunc

func ContentTypeCheckerMiddleware

func ContentTypeCheckerMiddleware() gin.HandlerFunc

func CorsHandler

func CorsHandler(cors *Cors) func(http.Handler) http.Handler

func GithubMiddleware

func GithubMiddleware(secret string) gin.HandlerFunc

GithubMiddleware returns a Handler that authenticates via GitHub's Authorization for Webhooks scheme (https://developer.github.com/webhooks/securing/#validating-payloads-from-github) Writes a http.StatusUnauthorized if authentication fails

func GzipHandler

func GzipHandler(compressionLevel int) func(http.Handler) http.Handler

Middleware that sends compresses the response with Gzip if supported by the client

func JsonHandler

func JsonHandler() func(http.Handler) http.Handler

Middleware that sends an application/json header

func LogHandler

func LogHandler() func(http.Handler) http.Handler

func LogWithTimingHandler

func LogWithTimingHandler() func(http.Handler) http.Handler

func RecoveryHandler

func RecoveryHandler() func(http.Handler) http.Handler

func RequestIdMiddleware

func RequestIdMiddleware() gin.HandlerFunc

func RevisionMiddleware

func RevisionMiddleware() gin.HandlerFunc

func SlowMiddleware

func SlowMiddleware(maxTime time.Duration, callback SlowHandlerFunc) gin.HandlerFunc

func TravisCIMiddleware

func TravisCIMiddleware(token string) gin.HandlerFunc

TravisCI returns a Handler that authenticates via Travis's Authorization for Webhooks scheme (http://docs.travis-ci.com/user/notifications/#Authorization-for-Webhooks) Writes a http.StatusUnauthorized if authentication fails

Types

type Cors

type Cors struct {
	// contains filtered or unexported fields
}

func DefaultCors

func DefaultCors() *Cors

Default creates a new Cors handler with default options

func NewCors

func NewCors(options Options) *Cors

New creates a new Cors handler with the provided options.

type Middleware

type Middleware struct {
	Chain []MiddlewareFunc
}

func New

func New() *Middleware

func (*Middleware) Handler

func (m *Middleware) Handler() http.Handler

func (*Middleware) Use

func (m *Middleware) Use(handler func(http.Handler) http.Handler)

func (*Middleware) UseHandler

func (m *Middleware) UseHandler(handler http.Handler)

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

type Options

type Options struct {
	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// Default value is ["*"]
	AllowedOrigins []string
	// AllowedMethods is a list of methods the client is allowed to use with
	// cross-domain requests.
	AllowedMethods []string
	// AllowedHeaders is list of non simple headers the client is allowed to use with
	// cross-domain requests. Default value is simple methods (GET and POST)
	AllowedHeaders []string
	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
	// API specification
	ExposedHeaders []string
	// AllowCredentials indicates whether the request can include user credentials like
	// cookies, HTTP authentication or client side SSL certificates.
	AllowCredentials bool
	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached
	MaxAge int
}

Options is a configuration container to setup the CORS middleware.

type SlowHandlerFunc

type SlowHandlerFunc func(ctx *gin.Context, duration time.Duration)

Jump to

Keyboard shortcuts

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