weather/web/util/response/code.go

110 lines
2.1 KiB
Go
Raw Normal View History

2025-01-02 22:57:51 +08:00
package response
const (
Success ResponseCode = 0
NoContent ResponseCode = 204
BadRequest ResponseCode = 400
Unauthorized ResponseCode = 401
TooManyRequests ResponseCode = 429
InternalServerError ResponseCode = 500
InvalidUserName ResponseCode = 40101
InvalidUserPassword ResponseCode = 40102
DBFailure ResponseCode = 50001
InvalidActionNum ResponseCode = 52000
InvalidBody ResponseCode = 1002
DataNotExist ResponseCode = 2002
DataIsExist ResponseCode = 2003
InvalidUserID ResponseCode = 3001
InvalidUserToken ResponseCode = 3004
InvalidUserRole ResponseCode = 3005
InvalidUserStatus ResponseCode = 3006
InvalidTemplateType ResponseCode = 60001
TemplateInUse ResponseCode = 60002
InvalidDriverType ResponseCode = 61001
DriverIsRun ResponseCode = 61002
ErrDataPointWrite ResponseCode = 7001
)
type ResponseCode uint32
func (r ResponseCode) String() string {
switch r {
case Success:
return "请求成功"
case NoContent:
return "无内容"
case BadRequest:
return "错误请求"
case Unauthorized:
return "未授权"
case TooManyRequests:
return "请求过多"
case InternalServerError:
return "服务器内部错误"
case DBFailure:
return "数据库操作失败"
case InvalidUserName:
return "无效的用户名"
case InvalidUserPassword:
return "无效的用户密码"
case InvalidActionNum:
return "无效的请求动作"
///////////////////////////////////////
// 1001-1003
case InvalidBody:
return "无效的请求体"
// 2001-2999 数据库相关
case DataNotExist:
return "数据不存在"
case DataIsExist:
return "数据已存在"
// 3001-3999 用户相关
case InvalidUserID:
return "无效的用户ID"
case InvalidUserToken:
return "无效的用户token"
case InvalidUserRole:
return "无效的用户权限"
case InvalidUserStatus:
return "无效的用户状态"
case InvalidTemplateType:
return "无效的模板类型"
case TemplateInUse:
return "模板使用中"
case InvalidDriverType:
return "无效的驱动类型"
case DriverIsRun:
return "驱动运行中"
// 96001
default:
return "未知的响应码"
}
}