Documentation ¶
Index ¶
- func ErrIsCode(err error, code int) bool
- func IteratorErr(fn func(*Err) error) error
- func MustRegisterErr(err *Err)
- func NewHandler(handler HandlerFunc) gin.HandlerFunc
- func NewHandlerFuncChain(handler ...HandlerFunc) gin.HandlerFunc
- func OverWriteErr(err *Err)
- func SetClaim(ctx context.Context, claim *Claim) context.Context
- func SetConfig(ctx context.Context, cfg *HTTPConf) context.Context
- type Claim
- type Context
- type Controller
- type Engine
- type Err
- type ErrResponse
- type HTTPConf
- type HandlerFunc
- type Health
- type IRoutes
- type Metrics
- type PageResponse
- type PaginationResponse
- type RegisterRoute
- type Response
- type TLS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(handler HandlerFunc) gin.HandlerFunc
func NewHandlerFuncChain ¶
func NewHandlerFuncChain(handler ...HandlerFunc) gin.HandlerFunc
Types ¶
type Claim ¶
type Claim struct { ID string // user id UserValue string // user value Secret string // secret for jwt Name string // username Token string ClientVersion string SinceTime time.Time TraceID string DBName string // 分库 TablePrefix string // 分表 Debug bool // if debug user logger will very detailed FakeTime string // faketime for debug mode user Extra map[string]interface{} `json:"extra"` }
type Context ¶
type Context interface { Context() context.Context GinContext() *gin.Context Send(data interface{}, err error) SendOk(data ...interface{}) // SendOk(data interface{}) SendErr(err error) SendErrCode(errcode int) SendParamErr(err ...error) SendInternalErr(err ...error) Stream(closer io.ReadCloser) HTML(tmpl string, data interface{}) Bind(param interface{}) error BindJSON(param interface{}) error BindUri(param interface{}) error BindQuery(param interface{}) error BindHeader(obj interface{}) error Param(key string) string Next() Abort() AbortWithStatus(code int) AbortWithStatusJSON(code int, jsonObj interface{}) GetHeader(key string) string Header(key, value string) Set(key string, value interface{}) Get(key string) (interface{}, bool) GetClaim() *Claim SetClaim(claim *Claim) }
func NewContext ¶
NewContext returns a new Context 1. 限制可以使用的方法; 2. 和添加默认处理;
func NewMockContext ¶
func NewMockContext() Context
type Controller ¶
type Controller interface {
Register(route IRoutes)
}
type Err ¶
type ErrResponse ¶
type HTTPConf ¶
type HTTPConf struct { Enable bool `default:"true"` Mode string `default:"release" opts:"release,debug,test"` BaseRoute string `default:""` ColorConsole bool `default:"false"` Port int `default:"8080"` Host string `default:"127.0.0.1"` ReadSecond int `default:"30"` WriteSecond int `default:"30"` ConnSecond int `default:"30"` ShutdownSecond int ` default:"30" validate:"min=1,max=60"` TLS TLS Metrics Metrics }
type HandlerFunc ¶
type HandlerFunc func(ctx Context)
func RequestLogger ¶
func RequestLogger(skip map[string]struct{}) HandlerFunc
type IRoutes ¶
type IRoutes interface { Use(...HandlerFunc) Group(string, ...HandlerFunc) IRoutes Handle(string, string, ...HandlerFunc) Any(string, ...HandlerFunc) GET(string, ...HandlerFunc) POST(string, ...HandlerFunc) DELETE(string, ...HandlerFunc) PATCH(string, ...HandlerFunc) PUT(string, ...HandlerFunc) OPTIONS(string, ...HandlerFunc) HEAD(string, ...HandlerFunc) StaticFile(string, string) Static(string, string) StaticFS(string, http.FileSystem) Context() context.Context }
IRoutes implements IRoutes; it's a wrapper around a gin.IRouter
type PageResponse ¶
type PageResponse struct { Page int64 `json:"page" example:"1"` PageSize int64 `json:"page_size" example:"10"` Total int64 `json:"total" example:"0"` Data interface{} `json:"data"` }
func NewPaginationRes ¶
func NewPaginationRes(total, page, pageSize int64, data interface{}) *PageResponse
type PaginationResponse ¶
type PaginationResponse struct { Response Data PageResponse `json:"data"` }
type RegisterRoute ¶
type RegisterRoute func(IRoutes)
type Response ¶
type Response struct { Trace string `json:"trace,omitempty" example:"uuid"` Success bool `json:"success" example:"true"` Code int `json:"code" example:"0"` Msg string `json:"msg" example:"ok"` Data interface{} `json:"data"` }
func NewErrorResponse ¶
func NewResponse ¶
func NewSuccessResponse ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.