Documentation
¶
Index ¶
Constants ¶
View Source
const ( //CodeSignFormater fromat error code to string CodeSignFormater = "S%05d" //CodeMissingClientID not found clientID error code CodeMissingClientID = iota //CodeMissingSign not found sign error code CodeMissingSign //CodeInvalidClientID invalid clientID error code CodeInvalidClientID //CodeInvalidSign invalid sign error code CodeInvalidSign //CodeReplayAttack replay attack error code CodeReplayAttack //CodeTimestampFormat timstamp format not use RCF3339 CodeTimestampFormat //CodeRequestExpired request expired CodeRequestExpired )
Variables ¶
View Source
var ErrorFormater = func(b *BaseError) string { return fmt.Sprintf("{\"code\":\"%s\", \"msg\":\"%s\"}", b.GetCode(), b.msg) }
ErrorFormater error formater type func(string, string)
View Source
var Pack = func(ctx *gin.Context, params ...interface{}) interface{} { flag := 0 result := &BaseResult{ Method: ctx.Request.Method, } for _, p := range params { if p == nil { continue } if e, ok := p.(IError); ok && flag&1 == 0 { result.Error = &ErrorResult{ Code: e.GetCode(), Msg: e.GetMsg(), } } else if e, ok := p.(error); ok && flag&1 == 0 { result.Error = &ErrorResult{ Msg: e.Error(), } } else if flag&2 == 1 { result.Data = p } } return result }
Pack pack data or error to map for result to client eg. Pack(ctx, data, err)
Pack(ctx, err) Pack(ctx, data)
Functions ¶
Types ¶
type BaseError ¶
type BaseError struct {
// contains filtered or unexported fields
}
BaseError base error
type BaseResult ¶
type BaseResult struct { APIVersion string ID string Method string Error interface{} Data interface{} }
BaseResult result formater
type ErrorResult ¶
ErrorResult error formater in result json