Documentation
¶
Index ¶
- Constants
- Variables
- func APIOutPut(c *gin.Context, msg string, data interface{})
- func APIOutPutError(c *gin.Context, msg string)
- func AuthErrorOut(c *gin.Context)
- func CSRFMiddleware() gin.HandlerFunc
- func CSRFTokenMiddleware() gin.HandlerFunc
- func FormSetCSRF(r *http.Request) template.HTML
- func GetPostArgs(c *gin.Context, obj interface{}) error
- func Handle(h HandlerFunc) gin.HandlerFunc
- func NewGinServer()
- func OutHtml()
- func OutPut(c *gin.Context, msg string, data interface{})
- func OutPutError(c *gin.Context, msg string)
- func ReqGrpcParameter(ctx *gin.Context, obj any) error
- func RespWriteGrpcFail(ctx *gin.Context, code GrpcErrorCode, err error)
- func RespWriteGrpcOK(ctx *gin.Context, data interface{})
- func SetCSRFTokenMiddleware(key string) gin.HandlerFunc
- func TokenInvalidOut(c *gin.Context)
- type CommonResp
- type GinCtx
- func (ctx *GinCtx) APIOutPut(data interface{}, msg string)
- func (ctx *GinCtx) APIOutPutError(err error, msg string)
- func (ctx *GinCtx) AuthErrorOut()
- func (ctx *GinCtx) GetIP() string
- func (ctx *GinCtx) GetLang() string
- func (ctx *GinCtx) GetParam(key string) string
- func (ctx *GinCtx) GetParamInt(key string) int
- func (ctx *GinCtx) GetParamInt64(key string) int64
- func (ctx *GinCtx) GetPostArgs(obj interface{}) error
- func (ctx *GinCtx) GetQuery(key string) string
- func (ctx *GinCtx) GetQueryInt(key string) int
- func (ctx *GinCtx) GetQueryInt64(key string) int64
- func (ctx *GinCtx) GetSource() string
- func (ctx *GinCtx) PageList(pg, number, count, size int, urlTemp string) []*Page
- func (ctx *GinCtx) PageListInt(pg, number, count, size int) []int
- type GrpcErrorCode
- type HandlerFunc
- type Page
- type ResponseCode
- type ResponseJson
Constants ¶
View Source
const ( ReqIP = "reqIp" Lang = "lang" // cn: 中文 Source = "source" // 来源,web:1, h5:2, android:3, ios:4 )
View Source
const ( SourceWeb = "1" SourceH5 = "2" SourceAndroid = "3" SourceIos = "4" )
Variables ¶
View Source
var ( CsrfName = "cToken" CsrfAuthKey = "123456789" )
View Source
var Router *gin.Engine
Functions ¶
func CSRFMiddleware ¶
func CSRFMiddleware() gin.HandlerFunc
CSRFMiddleware use: ginHelper.CsrfName = "CsrfName" ginHelper.CsrfAuthKey = "CsrfAuthKey" Router.Use(ginHelper.CSRFMiddleware())
func CSRFTokenMiddleware ¶
func CSRFTokenMiddleware() gin.HandlerFunc
func FormSetCSRF ¶
FormSetCSRF use:
c.HTML(http.StatusOK, "login.html", gin.H{
"csrf": ginHelper.FormSetCSRF(c.Request),
})
func Handle ¶
func Handle(h HandlerFunc) gin.HandlerFunc
func NewGinServer ¶
func NewGinServer()
func OutPutError ¶ added in v0.1.4
OutPutError 统一接口输出错误方法
func RespWriteGrpcFail ¶ added in v0.1.4
func RespWriteGrpcFail(ctx *gin.Context, code GrpcErrorCode, err error)
func RespWriteGrpcOK ¶ added in v0.1.4
func SetCSRFTokenMiddleware ¶
func SetCSRFTokenMiddleware(key string) gin.HandlerFunc
Types ¶
type CommonResp ¶ added in v0.1.4
type CommonResp struct {
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 错误代码
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // 成功响应数据
Msg string `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
Stack string `protobuf:"bytes,4,opt,name=stack,proto3" json:"stack,omitempty"` // 服务器内部错误时的调用栈(用于开发环境的调试使用)
// contains filtered or unexported fields
}
type GinCtx ¶
GinCtx 给gin context 扩展方法
func (*GinCtx) APIOutPutError ¶
func (*GinCtx) GetParamInt ¶
func (*GinCtx) GetParamInt64 ¶
func (*GinCtx) GetQueryInt ¶
func (*GinCtx) GetQueryInt64 ¶
func (*GinCtx) PageListInt ¶
type GrpcErrorCode ¶ added in v0.1.4
type GrpcErrorCode int32
const ( ErrorCode_NO GrpcErrorCode = 0 ErrorCode_UnKnow GrpcErrorCode = 1 //未知错误 ErrorCode_InternalServer GrpcErrorCode = 2 //内部服务错误 ErrorCode_RequestData GrpcErrorCode = 3 //请求数据错误 ErrorCode_InterfaceInvalid GrpcErrorCode = 4 //接口无效 ErrorCode_ServerStop GrpcErrorCode = 5 //服务已暂停 ErrorCode_ErrDBNoRecord GrpcErrorCode = 6 //没有记录 ErrorCode_Database GrpcErrorCode = 7 //数据错误 )
type HandlerFunc ¶
type HandlerFunc func(c *GinCtx)
type ResponseCode ¶ added in v0.1.4
type ResponseCode int64
ResponseCode 统一接口输出码
const ( SuccessCode ResponseCode = 0 // 接口成功 ErrorCode ResponseCode = 1 // 接口内部错误(业务错误,msg显示具体信息) ParamViolation ResponseCode = 2 // 参数不合法 InterfaceInvalid ResponseCode = 3 // 接口无效 ServerStop ResponseCode = 4 // 服务已暂停 DataNone ResponseCode = 5 // 接口没查询到数据 TokenInvalid ResponseCode = 1001 // token无效 TokenExpire ResponseCode = 1002 // token已过期 NoPermissions ResponseCode = 1003 // 没有权限访问 )
type ResponseJson ¶
type ResponseJson struct {
Code ResponseCode `json:"code"`
Msg string `json:"msg"`
Date any `json:"data"`
TimeStamp int64 `json:"timestamp"`
}
ResponseJson 统一接口输出
Click to show internal directories.
Click to hide internal directories.