Documentation ¶
Index ¶
- func Auth(secretKey string) gin.HandlerFunc
- func CORS(opt *CORSOptions) gin.HandlerFunc
- func HasRole(roles ...string) gin.HandlerFunc
- func Lang(langs ...string) gin.HandlerFunc
- func Maintenance(cb MaintenanceFunc) gin.HandlerFunc
- func RequestClaims(c *gin.Context) (ujwt.Claims, bool)
- func RequestLang(c *gin.Context) language.Tag
- type CORSOptions
- type MaintenanceFunc
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 ¶
RequestClaims returns the request claims.
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 ¶
MaintenanceFunc is a callback which returns true if server is in maintenance mode.