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 UnknownError = "unknown"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ErrNil 正常
|
// ErrorNil 正常
|
||||||
ErrNil = 0
|
ErrorNil = 0
|
||||||
// ErrSystemError 系统错误
|
// ErrorInternalServer 系统错误
|
||||||
ErrSystemError = -1
|
ErrorInternalServer = 500
|
||||||
// ErrProcessPanic 服务PANIC
|
// ErrorNotImplemented 方法没有实现
|
||||||
ErrProcessPanic = -10
|
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 (
|
// ErrorFreqLimit 路由频率限制 [业务级]
|
||||||
// ErrInvalidArg 请求参数无效
|
ErrorFreqLimit = 1004
|
||||||
ErrInvalidArg = 1001
|
// ErrorRequestBroken 请求熔断
|
||||||
// ErrRecordNotFound 找不到记录
|
ErrorRequestBroken = 1005
|
||||||
ErrRecordNotFound = 1002
|
// ErrorRequestRateLimit 请求流控 [服务级]
|
||||||
// ErrConnectTimeout 连接超时
|
ErrorRequestRateLimit = 1006
|
||||||
ErrConnectTimeout = 1003
|
// ErrorParamEmpty 请求参数为空
|
||||||
// ErrFreqLimit 频率限制 [业务级]
|
ErrorParamEmpty = 1007
|
||||||
ErrFreqLimit = 1004
|
|
||||||
// ErrRequestBroken 请求熔断
|
|
||||||
ErrRequestBroken = 1005
|
|
||||||
// ErrRequestRateLimit 请求限流 [服务级]
|
|
||||||
ErrRequestRateLimit = 1006
|
|
||||||
// ErrParamEmpty 请求参数为空
|
|
||||||
ErrParamEmpty = 1007
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errCodeMap = map[int32]string{
|
errCodeMap = map[int32]string{
|
||||||
ErrNil: "ok",
|
ErrorNil: "ok",
|
||||||
ErrSystemError: "system error",
|
ErrorInternalServer: "internal server error",
|
||||||
ErrProcessPanic: "process panic",
|
ErrorNotImplemented: "method not implemented",
|
||||||
ErrInvalidArg: "invalid arg",
|
ErrorBadGateway: "bad gateway",
|
||||||
ErrRecordNotFound: "record not found",
|
ErrorServiceUnavailable: "service unavailable",
|
||||||
ErrConnectTimeout: "connect timeout",
|
ErrorGatewayTimeout: "gateway timeout",
|
||||||
ErrFreqLimit: "request freq limit",
|
ErrorBadRequest: "bad request",
|
||||||
ErrRequestBroken: "request is broken",
|
ErrorUnauthorized: "unauthorized",
|
||||||
ErrRequestRateLimit: "request rate is limited",
|
ErrorPaymentRequired: "payment required",
|
||||||
ErrParamEmpty: "request param is empty",
|
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 (
|
require (
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
github.com/go-playground/validator/v10 v10.15.5
|
github.com/go-playground/validator/v10 v10.19.0
|
||||||
github.com/gorilla/schema v1.2.0
|
github.com/gorilla/schema v1.3.0
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
google.golang.org/protobuf v1.31.0
|
google.golang.org/protobuf v1.33.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
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/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/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||||
github.com/leodido/go-urn v1.2.4 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.19 // 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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // 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/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
golang.org/x/arch v0.5.0 // indirect
|
golang.org/x/arch v0.7.0 // indirect
|
||||||
golang.org/x/crypto v0.14.0 // indirect
|
golang.org/x/crypto v0.22.0 // indirect
|
||||||
golang.org/x/net v0.17.0 // indirect
|
golang.org/x/net v0.24.0 // indirect
|
||||||
golang.org/x/sys v0.13.0 // indirect
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
golang.org/x/text v0.13.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // 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())
|
err := r.bindAndValidate(c, req.Interface())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, Result{
|
c.JSON(http.StatusOK, Result{
|
||||||
ErrCode: ErrInvalidArg,
|
ErrCode: ErrorBadRequest,
|
||||||
ErrMsg: err.Error(),
|
ErrMsg: err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -282,7 +282,7 @@ func (r *Register) getCallFunc(rFunc, rGroup reflect.Value) (gin.HandlerFunc, er
|
||||||
if rerr == nil {
|
if rerr == nil {
|
||||||
c.Writer.WriteHeader(http.StatusOK)
|
c.Writer.WriteHeader(http.StatusOK)
|
||||||
respData, _ := jsoniter.Marshal(Result{
|
respData, _ := jsoniter.Marshal(Result{
|
||||||
ErrCode: ErrNil,
|
ErrCode: ErrorNil,
|
||||||
ErrMsg: "ok",
|
ErrMsg: "ok",
|
||||||
Data: resp,
|
Data: resp,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue