middlewares

package
v0.0.0-...-1606966 Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllowOriginKey      string = "Access-Control-Allow-Origin"
	AllowCredentialsKey        = "Access-Control-Allow-Credentials"
	AllowHeadersKey            = "Access-Control-Allow-Headers"
	AllowMethodsKey            = "Access-Control-Allow-Methods"
	MaxAgeKey                  = "Access-Control-Max-Age"

	OriginKey         = "Origin"
	RequestMethodKey  = "Access-Control-Request-Method"
	RequestHeadersKey = "Access-Control-Request-Headers"
	ExposeHeadersKey  = "Access-Control-Expose-Headers"
)

Variables

This section is empty.

Functions

func AdminMiddleware

func AdminMiddleware() gin.HandlerFunc

func AuthMiddleware

func AuthMiddleware() gin.HandlerFunc

AuthMiddleware that handles token management

func ConfigMiddleware

func ConfigMiddleware(viper *viper.Viper) gin.HandlerFunc

func CorsMiddleware

func CorsMiddleware(config Config) gin.HandlerFunc

Middleware generates a middleware handler function that works inside of a Gin request to set the correct CORS headers. It accepts a cors.Options struct for configuration.

func EmailMiddleware

func EmailMiddleware(emailSender services.EmailSender) gin.HandlerFunc

func ErrorMiddleware

func ErrorMiddleware() gin.HandlerFunc

func RateMiddleware

func RateMiddleware() gin.HandlerFunc

func RedisMiddleware

func RedisMiddleware(redis *services.Redis) gin.HandlerFunc

func StoreMiddleware

func StoreMiddleware(db *mgo.Database) gin.HandlerFunc

Middleware that handles store layer

Types

type Config

type Config struct {
	// Enabling this causes us to compare Request-Method and Request-Headers to confirm they contain a subset of the Allowed Methods and Allowed Headers
	// The spec however allows for the server to always match, and simply return the allowed methods and headers. Either is supported in this middleware.
	ValidateHeaders bool

	// Comma delimited list of origin domains. Wildcard "*" is also allowed, and matches all origins.
	// If the origin does not match an item in the list, then the request is denied.
	Origins string

	// This are the headers that the resource supports, and will accept in the request.
	// Default is "Authorization".
	RequestHeaders string

	// These are headers that should be accessible by the CORS client, they are in addition to those defined by the spec as "simple response headers"
	//	 Cache-Control
	//	 Content-Language
	//	 Content-Type
	//	 Expires
	//	 Last-Modified
	//	 Pragma
	ExposedHeaders string

	// Comma delimited list of acceptable HTTP methods.
	Methods string

	// The amount of time in seconds that the client should cache the Preflight request
	MaxAge time.Duration

	// If true, then cookies and Authorization headers are allowed along with the request.  This
	// is passed to the browser, but is not enforced.
	Credentials bool
	// contains filtered or unexported fields
}

Config defines the configuration options available to control how the CORS middleware should function.

Jump to

Keyboard shortcuts

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