Documentation
¶
Index ¶
- Constants
- Variables
- func ErrPanic(err error)
- func GetCtxLog(ctx context.Context) *zap.SugaredLogger
- func GetGinCtxAny[T any](c *gin.Context, key string) (ret T)
- func GetLogFromGinContext(c *gin.Context) *zap.SugaredLogger
- func NewE(err error, sts StatusItf) *httpError
- func Result(c *gin.Context, data interface{}, err error)
- func Serve(c *HttpServerConfig) error
- func SetCtxLog(ctx context.Context, log *zap.SugaredLogger) context.Context
- func SetLogger(l zlog.Logger)
- type BaseParam
- type HttpServerConfig
- type StatusItf
Constants ¶
View Source
const ( ProxyAuthorizationHeader = "Proxy-Authorization" OpenAiAuthorizationHeader = "Authorization" ProxyUserHeader = "Fast-user" ProxyPasswdHeader = "Fast-passwd" ClaimsKey = "claims" EmailKey = "email" RequestIDKey = "Request-Id" GRPCRequestIDKey = "request-id" RequestIDLogKey = "requestIDLog" )
Variables ¶
View Source
var ( OK = StatusItf(status{httpStatusCode: http.StatusOK, code: 0, message: "OK"}) ErrUnknown = StatusItf(status{httpStatusCode: http.StatusInternalServerError, code: 99999, message: "The error unknown"}) ErrPermission = StatusItf(status{httpStatusCode: http.StatusForbidden, code: 10001, message: "Need to check permissions"}) ErrServerPanic = StatusItf(status{httpStatusCode: http.StatusInternalServerError, code: 10002, message: "Server error"}) // system errors ErrAuthentication = StatusItf(status{httpStatusCode: http.StatusUnauthorized, code: 20001, message: "Authentication failed"}) ErrCreate = StatusItf(status{httpStatusCode: http.StatusBadRequest, code: 20002, message: "Create failed"}) ErrParameterMatch = StatusItf(status{httpStatusCode: http.StatusBadRequest, code: 20003, message: "Parameter binding failed"}) ErrDelete = StatusItf(status{httpStatusCode: http.StatusBadRequest, code: 20004, message: "Delete failed"}) ErrGet = StatusItf(status{httpStatusCode: http.StatusBadRequest, code: 20005, message: "Get failed"}) ErrUpdate = StatusItf(status{httpStatusCode: http.StatusBadRequest, code: 20006, message: "Update failed"}) )
所有错误都应当设立对应的错误码,保证敏感信息不会暴露,未定义的错误类型统一返回ErrUnknown 五位错误码规则: 第一位错误的类型 第二、三位错误出现的模块 第四、五位为该模块内部的错误
Functions ¶
func GetLogFromGinContext ¶
func GetLogFromGinContext(c *gin.Context) *zap.SugaredLogger
func Serve ¶
func Serve(c *HttpServerConfig) error
Types ¶
Click to show internal directories.
Click to hide internal directories.