Documentation ¶
Index ¶
- Constants
- func FromGinContext(ctx context.Context) (c *gin.Context, ok bool)
- func Handle(h HandlerFunc) gin.HandlerFunc
- func HealthCheck(c *gin.Context)
- func Middlewares(m ...middleware.Middleware) gin.HandlerFunc
- func NewGinContext(ctx context.Context, c *gin.Context) context.Context
- type Context
- func (c *Context) Error(err error)
- func (c *Context) GetClientLocale() string
- func (c *Context) GetClientTimezoneOffset() (int16, error)
- func (c *Context) GetRequestId() string
- func (c *Context) JSON(httpStatus int, resp Result)
- func (c *Context) JSONE(code int, msg string, data any)
- func (c *Context) JSONOK(msg string, data any)
- func (c *Context) RouteNotFound()
- func (c *Context) SetRequestId(requestId string)
- func (c *Context) Success(data any)
- type HandlerFunc
- type Result
Constants ¶
const ( // AcceptLanguageHeaderName represents the header name of accept language AcceptLanguageHeaderName = "Accept-Language" // ClientTimezoneOffsetHeaderName represents the header name of client timezone offset ClientTimezoneOffsetHeaderName = "X-Timezone-Offset" )
const ( // CodeOK means a successful response CodeOK = 0 // CodeErr means a failure response CodeErr = 1 )
Variables ¶
This section is empty.
Functions ¶
func FromGinContext ¶
FromGinContext returns the gin.Context value stored in ctx, if any.
func Handle ¶
func Handle(h HandlerFunc) gin.HandlerFunc
Handle convert HandlerFunc to gin.HandlerFunc
func HealthCheck ¶
HealthCheck will return OK if the underlying BoltDB is healthy. At least healthy enough for demoing purposes.
func Middlewares ¶
func Middlewares(m ...middleware.Middleware) gin.HandlerFunc
Middlewares return middlewares wrapper
Types ¶
type Context ¶
Context a wrapper of gin.Context
func WrapContext ¶
WrapContext returns a context wrapped by this file
func (*Context) GetClientLocale ¶
GetClientLocale returns the client locale name
func (*Context) GetClientTimezoneOffset ¶
GetClientTimezoneOffset returns the client timezone offset
func (*Context) GetRequestId ¶
GetRequestId returns the current request id
func (*Context) JSON ¶
JSON returns JSON response e.x. {"code":<code>, "msg":<msg>, "data":<data>, "details":<details>}
func (*Context) JSONE ¶
JSONE returns JSON response with failure business code ,msg and data e.x. {"code":<code>, "msg":<msg>, "data":<data>}
func (*Context) JSONOK ¶
JSONOK returns JSON response with successful business code and data e.x. {"code":0, "msg":"成功", "data":<data>}
func (*Context) SetRequestId ¶
SetRequestId sets the given request id to context
type HandlerFunc ¶
type HandlerFunc func(c *Context)
HandlerFunc defines the handler to wrap gin.Context