ginx

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// CodeOK means a successful response
	CodeOK = 0
	// CodeErr means a failure response
	CodeErr = 1
)

Variables

This section is empty.

Functions

func FromGinContext

func FromGinContext(ctx context.Context) (c *gin.Context, ok bool)

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

func HealthCheck(c *gin.Context)

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

func NewGinContext

func NewGinContext(ctx context.Context, c *gin.Context) context.Context

NewGinContext returns a new Context that carries gin.Context value.

Types

type Context

type Context struct {
	*gin.Context
}

Context a wrapper of gin.Context

func WrapContext

func WrapContext(c *gin.Context) *Context

WrapContext returns a context wrapped by this file

func (*Context) Error

func (c *Context) Error(err error)

func (*Context) GetClientLocale

func (c *Context) GetClientLocale() string

GetClientLocale returns the client locale name

func (*Context) GetClientTimezoneOffset

func (c *Context) GetClientTimezoneOffset() (int16, error)

GetClientTimezoneOffset returns the client timezone offset

func (*Context) GetRequestId

func (c *Context) GetRequestId() string

GetRequestId returns the current request id

func (*Context) JSON

func (c *Context) JSON(httpStatus int, resp Result)

JSON returns JSON response e.x. {"code":<code>, "msg":<msg>, "data":<data>, "details":<details>}

func (*Context) JSONE

func (c *Context) JSONE(code int, msg string, data any)

JSONE returns JSON response with failure business code ,msg and data e.x. {"code":<code>, "msg":<msg>, "data":<data>}

func (*Context) JSONOK

func (c *Context) JSONOK(msg string, data any)

JSONOK returns JSON response with successful business code and data e.x. {"code":0, "msg":"成功", "data":<data>}

func (*Context) RouteNotFound

func (c *Context) RouteNotFound()

RouteNotFound 未找到相关路由

func (*Context) SetRequestId

func (c *Context) SetRequestId(requestId string)

SetRequestId sets the given request id to context

func (*Context) Success

func (c *Context) Success(data any)

type HandlerFunc

type HandlerFunc func(c *Context)

HandlerFunc defines the handler to wrap gin.Context

type Result

type Result struct {
	Code    int      `json:"code"`
	Msg     string   `json:"msg"`
	Data    any      `json:"data"`
	Details []string `json:"details,omitempty"`
}

Result defines HTTP JSON response

Jump to

Keyboard shortcuts

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