Skip to content

Instantly share code, notes, and snippets.

@brainwire
Created August 26, 2018 08:43
Show Gist options
  • Save brainwire/0281185b6a58e614a9fffb51d7003a91 to your computer and use it in GitHub Desktop.
Save brainwire/0281185b6a58e614a9fffb51d7003a91 to your computer and use it in GitHub Desktop.
GoLang Err
var (
ErrSuccess = StandardError{0, "成功"}
ErrUnrecognized = StandardError{-1, "未知错误"}
ErrAccessForbid = StandardError{1000, "没有访问权限"}
ErrNamePwdIncorrect = StandardError{1001, "用户名或密码错误"}
ErrAuthExpired = StandardError{1002, "证书过期"}
ErrAuthInvalid = StandardError{1003, "无效签名"}
ErrClientInnerError = StandardError{4000, "客户端内部错误"}
ErrParamError = StandardError{4001, "参数错误"}
ErrReqForbidden = StandardError{4003, "请求被拒绝"}
ErrPathNotFount = StandardError{4004, "请求路径不存在"}
ErrMethodIncorrect = StandardError{4005, "请求方法错误"}
ErrTimeout = StandardError{4006, "服务超时"}
ErrServerUnavailable = StandardError{5000, "服务不可用"}
ErrDbQueryError = StandardError{5001, "数据库查询错误"}
)
//StandardError 标准错误,包含错误码和错误信息
type StandardError struct {
ErrorCode int `json:"errorCode"`
ErrorMsg string `json:"errorMsg"`
}
// Error 实现了 Error接口
func (err StandardError) Error() string {
return fmt.Sprintf("errorCode: %d, errorMsg %s", err.ErrorCode, err.ErrorMsg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment