gim

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: MIT Imports: 6 Imported by: 0

README

Gin Middlewares

Go Version GoDoc License

Gim is a series of handy middlewares to used with Gin framework.

License

Gim is published under MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(secretKey string) gin.HandlerFunc

Auth is the middleware for handling authentication.

func CORS added in v0.2.0

func CORS(opt *CORSOptions) gin.HandlerFunc

CORS is a middleware to handle cross-origin resource sharing control.

func HasRole

func HasRole(roles ...string) gin.HandlerFunc

HasRole is the middleware for allowing specific roles to access a resource.

If the authenticated user does not have at-least one role in the allowed roles, it will be reported back by an access forbidden error. It has no effects if roles are empty.

Note: HasRole middleware must always come after Auth middleware.

func Lang

func Lang(langs ...string) gin.HandlerFunc

Lang is the middleware for parsing Accept-Language header.

func Maintenance

func Maintenance(cb MaintenanceFunc) gin.HandlerFunc

Maintenance is the middleware which checks server serviceability and responds with a 503 status code if the server is in maintenance mode.

func RequestClaims

func RequestClaims(c *gin.Context) (ujwt.Claims, bool)

RequestClaims returns the request claims.

func RequestLang

func RequestLang(c *gin.Context) language.Tag

RequestLang returns the request language.

Types

type CORSOptions added in v0.2.0

type CORSOptions struct {
	// Origins are the origins which are allowed to access resources on
	// this server. A nil or empty list accepts all origins.
	Origins []string

	// Methods is the list of methods which are acceptable.
	Methods []string

	// Methods is the list of headers which are acceptable.
	Headers []string

	// AllowCredentials determines if clients are allowed to send cookies or
	// HTTP authentication.
	AllowCredentials bool

	// MaxAge is the maximum duration in seconds which CORS headers are valid.
	MaxAge int

	// Permissive determines if requests without `Origin` should be accepted.
	// Permitted requests will not receive CORS headers.
	Permissive bool
}

CORSOptions are parameters used to configure CORS middleware.

type MaintenanceFunc

type MaintenanceFunc func() (bool, error)

MaintenanceFunc is a callback which returns true if server is in maintenance mode.

Jump to

Keyboard shortcuts

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