reflect: renew ErrMsg
This commit is contained in:
parent
cb23d9e80d
commit
28e8014aad
88
errcode.go
88
errcode.go
|
@ -5,43 +5,67 @@ import "fmt"
|
|||
const UnknownError = "unknown"
|
||||
|
||||
const (
|
||||
// ErrNil 正常
|
||||
ErrNil = 0
|
||||
// ErrSystemError 系统错误
|
||||
ErrSystemError = -1
|
||||
// ErrProcessPanic 服务PANIC
|
||||
ErrProcessPanic = -10
|
||||
)
|
||||
// ErrorNil 正常
|
||||
ErrorNil = 0
|
||||
// ErrorInternalServer 系统错误
|
||||
ErrorInternalServer = 500
|
||||
// ErrorNotImplemented 方法没有实现
|
||||
ErrorNotImplemented = 501
|
||||
// ErrorBadGateway 网关错误
|
||||
ErrorBadGateway = 502
|
||||
// ErrorServiceUnavailable 服务不可用
|
||||
ErrorServiceUnavailable = 503
|
||||
// ErrorGatewayTimeout 网关超时
|
||||
ErrorGatewayTimeout = 504
|
||||
// ErrorBadRequest 请求参数无效
|
||||
ErrorBadRequest = 400
|
||||
// ErrorUnauthorized 未授权访问
|
||||
ErrorUnauthorized = 401
|
||||
// ErrorPaymentRequired 缺少参数
|
||||
ErrorPaymentRequired = 402
|
||||
// ErrorForbidden 禁止访问
|
||||
ErrorForbidden = 403
|
||||
// ErrorNotFound 找不到记录
|
||||
ErrorNotFound = 404
|
||||
// ErrorMethodNotAllowed 请求不被允许
|
||||
ErrorMethodNotAllowed = 405
|
||||
// ErrorNotAcceptable 不被接受的请求
|
||||
ErrorNotAcceptable = 406
|
||||
// ErrorProxyAuthenticationRequired 代理需要授权
|
||||
ErrorProxyAuthenticationRequired = 407
|
||||
// ErrorRequestTimeout 请求超时
|
||||
ErrorRequestTimeout = 408
|
||||
// ErrorConflict 资源冲突
|
||||
ErrorConflict = 409
|
||||
|
||||
const (
|
||||
// ErrInvalidArg 请求参数无效
|
||||
ErrInvalidArg = 1001
|
||||
// ErrRecordNotFound 找不到记录
|
||||
ErrRecordNotFound = 1002
|
||||
// ErrConnectTimeout 连接超时
|
||||
ErrConnectTimeout = 1003
|
||||
// ErrFreqLimit 频率限制 [业务级]
|
||||
ErrFreqLimit = 1004
|
||||
// ErrRequestBroken 请求熔断
|
||||
ErrRequestBroken = 1005
|
||||
// ErrRequestRateLimit 请求限流 [服务级]
|
||||
ErrRequestRateLimit = 1006
|
||||
// ErrParamEmpty 请求参数为空
|
||||
ErrParamEmpty = 1007
|
||||
// ErrorFreqLimit 路由频率限制 [业务级]
|
||||
ErrorFreqLimit = 1004
|
||||
// ErrorRequestBroken 请求熔断
|
||||
ErrorRequestBroken = 1005
|
||||
// ErrorRequestRateLimit 请求流控 [服务级]
|
||||
ErrorRequestRateLimit = 1006
|
||||
// ErrorParamEmpty 请求参数为空
|
||||
ErrorParamEmpty = 1007
|
||||
)
|
||||
|
||||
var (
|
||||
errCodeMap = map[int32]string{
|
||||
ErrNil: "ok",
|
||||
ErrSystemError: "system error",
|
||||
ErrProcessPanic: "process panic",
|
||||
ErrInvalidArg: "invalid arg",
|
||||
ErrRecordNotFound: "record not found",
|
||||
ErrConnectTimeout: "connect timeout",
|
||||
ErrFreqLimit: "request freq limit",
|
||||
ErrRequestBroken: "request is broken",
|
||||
ErrRequestRateLimit: "request rate is limited",
|
||||
ErrParamEmpty: "request param is empty",
|
||||
ErrorNil: "ok",
|
||||
ErrorInternalServer: "internal server error",
|
||||
ErrorNotImplemented: "method not implemented",
|
||||
ErrorBadGateway: "bad gateway",
|
||||
ErrorServiceUnavailable: "service unavailable",
|
||||
ErrorGatewayTimeout: "gateway timeout",
|
||||
ErrorBadRequest: "bad request",
|
||||
ErrorUnauthorized: "unauthorized",
|
||||
ErrorPaymentRequired: "payment required",
|
||||
ErrorForbidden: "forbidden",
|
||||
ErrorNotFound: "not found",
|
||||
ErrorMethodNotAllowed: "method not allowed",
|
||||
ErrorNotAcceptable: "not acceptable",
|
||||
ErrorProxyAuthenticationRequired: "proxy authentication is required",
|
||||
ErrorRequestTimeout: "request timeout",
|
||||
ErrorConflict: "conflict",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
30
go.mod
30
go.mod
|
@ -4,35 +4,35 @@ go 1.20
|
|||
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-playground/validator/v10 v10.15.5
|
||||
github.com/gorilla/schema v1.2.0
|
||||
github.com/go-playground/validator/v10 v10.19.0
|
||||
github.com/gorilla/schema v1.3.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
google.golang.org/protobuf v1.31.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/bytedance/sonic v1.11.3 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/arch v0.5.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
@ -252,7 +252,7 @@ func (r *Register) getCallFunc(rFunc, rGroup reflect.Value) (gin.HandlerFunc, er
|
|||
err := r.bindAndValidate(c, req.Interface())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, Result{
|
||||
ErrCode: ErrInvalidArg,
|
||||
ErrCode: ErrorBadRequest,
|
||||
ErrMsg: err.Error(),
|
||||
})
|
||||
return
|
||||
|
@ -282,7 +282,7 @@ func (r *Register) getCallFunc(rFunc, rGroup reflect.Value) (gin.HandlerFunc, er
|
|||
if rerr == nil {
|
||||
c.Writer.WriteHeader(http.StatusOK)
|
||||
respData, _ := jsoniter.Marshal(Result{
|
||||
ErrCode: ErrNil,
|
||||
ErrCode: ErrorNil,
|
||||
ErrMsg: "ok",
|
||||
Data: resp,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue