Documentation ¶
Overview ¶
A Default Config for example is below:
cors.Config{ Origins: "*", Methods: "GET, PUT, POST, DELETE", RequestHeaders: "Origin, Authorization, Content-Type", ExposedHeaders: "", MaxAge: 1 * time.Minute, Credentials: true, ValidateHeaders: false, }
Package gzip provider a nice middleware for compress to responses.
Package accesslog provider a nice middleware for log http access.
Package recovery provider a nice middleware which recovers from panics anywhere in the chain.
Index ¶
Constants ¶
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" )
const ( HEADER_ACCEPT_ENCODING = "Accept-Encoding" HEADER_CONTENT_ENCODING = "Content-Encoding" HEADER_CONTENT_LENGTH = "Content-Length" HEADER_CONTENT_TYPE = "Content-Type" HEADER_VARY = "Vary" SCHEME = "gzip" )
Variables ¶
This section is empty.
Functions ¶
func Cors ¶
func Cors(config Config) nice.HandlerFunc
Cors 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 Gzip ¶
func Gzip(opt Options) nice.HandlerFunc
Gzip returns a nice middleware for compress to responses
func Recovery ¶
func Recovery() nice.HandlerFunc
Recovery returns a nice middleware which recovers from panics anywhere in the chain and handles the control to the centralized HTTPErrorHandler.
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 accessable 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.
type Options ¶
type Options struct { // Compression level. Can be DefaultCompression(-1), ConstantCompression(-2) // or any integer value between BestSpeed(1) and BestCompression(9) inclusive. CompressionLevel int }
Options represents a struct for specifying configuration options for the GZip middleware.