Documentation
¶
Index ¶
- Constants
- func AllowContentType(types ...string) gin.HandlerFunc
- func AllowJSON() gin.HandlerFunc
- func GetPrincipal(c *gin.Context) (jwt.User, bool)
- func HandleErrors() gin.HandlerFunc
- func Logger(skip ...string) gin.HandlerFunc
- func Metrics() gin.HandlerFunc
- func MustGetPrincipal(c *gin.Context) (jwt.User, error)
- func NewCustomRouter(healthCheck HealthFunc, middlewares ...gin.HandlerFunc) *gin.Engine
- func NewRouter(appName string, healthCheck HealthFunc) *gin.Engine
- func ParseQueryValue(c *gin.Context, key string) (string, error)
- func ParseQueryValues(c *gin.Context, key string) ([]string, error)
- func RequestID(key string) gin.HandlerFunc
- func SendOK(c *gin.Context)
- func Trace(app string, headers ...string) gin.HandlerFunc
- type Error
- func BadGatewayError(err error) *Error
- func BadGatewayf(format string, a ...interface{}) *Error
- func BadRequestError(err error) *Error
- func BadRequestf(format string, a ...interface{}) *Error
- func ConflictError(err error) *Error
- func Conflictf(format string, a ...interface{}) *Error
- func Errorf(status int, format string, a ...interface{}) *Error
- func ForbiddenError(err error) *Error
- func Forbiddenf(format string, a ...interface{}) *Error
- func InternalServerError(err error) *Error
- func InternalServerErrorf(format string, a ...interface{}) *Error
- func MethodNotAllowedError(err error) *Error
- func MethodNotAllowedf(format string, a ...interface{}) *Error
- func NewError(message string, status int, err error) *Error
- func NotFoundError(err error) *Error
- func NotFoundf(format string, a ...interface{}) *Error
- func NotImplementedError(err error) *Error
- func NotImplementedf(format string, a ...interface{}) *Error
- func PreconditionRequiredError(err error) *Error
- func PreconditionRequiredf(format string, a ...interface{}) *Error
- func ServiceUnavailableError(err error) *Error
- func ServiceUnavailablef(format string, a ...interface{}) *Error
- func TooManyRequestsError(err error) *Error
- func TooManyRequestsf(format string, a ...interface{}) *Error
- func UnauthorizedError(err error) *Error
- func Unauthorizedf(format string, a ...interface{}) *Error
- func UnsupportedMediaTypeError(err error) *Error
- func UnsupportedMediaTypef(format string, a ...interface{}) *Error
- type HealthFunc
- type RBAC
Constants ¶
const ( RequestIDHeader = "X-Request-ID" ClientIDHeader = "X-Client-ID" SessionIDHeader = "X-Session-ID" )
Common tracing headers
Variables ¶
This section is empty.
Functions ¶
func AllowContentType ¶
func AllowContentType(types ...string) gin.HandlerFunc
AllowContentType whitelists a given list of content types.
func AllowJSON ¶
func AllowJSON() gin.HandlerFunc
AllowJSON only allowes request with content type json.
func GetPrincipal ¶
GetPrincipal returns the authenticated user if exists.
func HandleErrors ¶
func HandleErrors() gin.HandlerFunc
HandleErrors wrapper function to deal with encountered errors during request handling.
func Logger ¶
func Logger(skip ...string) gin.HandlerFunc
Logger request logging middleware. Accepts a list of paths to skip logging incomming requests and non 500 outgoing requests to.
func MustGetPrincipal ¶
MustGetPrincipal returns the authenticated user or an error if none exists.
func NewCustomRouter ¶
func NewCustomRouter(healthCheck HealthFunc, middlewares ...gin.HandlerFunc) *gin.Engine
NewCustomRouter creates a new router with a custom list of base middlewares.
func NewRouter ¶
func NewRouter(appName string, healthCheck HealthFunc) *gin.Engine
NewRouter creates a default router.
func ParseQueryValue ¶
ParseQueryValue parses a query value from request.
func ParseQueryValues ¶
ParseQueryValues parses query values from a request.
func RequestID ¶
func RequestID(key string) gin.HandlerFunc
RequestID ensures that a request contains a request id. If not sets a UUID as there request id.
Types ¶
type Error ¶
type Error struct { ID string `json:"id,omitempty"` Status int `json:"status,omitempty"` Message string `json:"message,omitempty"` Err error `json:"-"` }
Error error containing status code and error.
func BadGatewayError ¶
BadGatewayError creates a 502 - Bad Gateway error.
func BadGatewayf ¶
BadGatewayf creates a 502 - Bad Gateway error.
func BadRequestError ¶
BadRequestError creates a 400 - Bad Request error.
func BadRequestf ¶
BadRequestf creates a 400 - Bad Request error.
func ConflictError ¶
ConflictError creates a 409 - Conflict error.
func ForbiddenError ¶
ForbiddenError creates a 403 - Forbidden error.
func Forbiddenf ¶
Forbiddenf creates a 403 - Forbidden error.
func InternalServerError ¶
InternalServerError creates a 500 - Internal Server Error.
func InternalServerErrorf ¶
InternalServerErrorf creates a 500 - Internal Server Error.
func MethodNotAllowedError ¶
MethodNotAllowedError creates a 405 - Method Not Allowed error.
func MethodNotAllowedf ¶
MethodNotAllowedf creates a 405 - Method Not Allowed error.
func NewError ¶
NewError creates a new Error based on a supplied status code attempts to derive the error message.
func NotFoundError ¶
NotFoundError creates a 404 - Not Found error.
func NotImplementedError ¶
NotImplementedError creates a 501 - Not Implemented error.
func NotImplementedf ¶
NotImplementedf creates a 501 - Not Implemented error.
func PreconditionRequiredError ¶
PreconditionRequiredError creates a 428 - Precondition Required error.
func PreconditionRequiredf ¶
PreconditionRequiredf creates a 428 - Precondition Required error.
func ServiceUnavailableError ¶
ServiceUnavailableError creates a 503 - Service Unavailable error.
func ServiceUnavailablef ¶
ServiceUnavailablef creates a 503 - Service Unavailable error.
func TooManyRequestsError ¶
TooManyRequestsError creates a 429 - Too Many Requests error.
func TooManyRequestsf ¶
TooManyRequestsf creates a 429 - Too Many Requests error.
func UnauthorizedError ¶
UnauthorizedError creates a 401 - Unauthorized error.
func Unauthorizedf ¶
Unauthorizedf creates a 401 - Unauthorized error.
func UnsupportedMediaTypeError ¶
UnsupportedMediaTypeError creates a 415 - Unsupported Media Type error.
func UnsupportedMediaTypef ¶
UnsupportedMediaTypef creates a 415 - Unsupported Media Type error.