golang错误码配置
//配置文件
package models const ( RECODE_OK = "0" RECODE_DBERR = "4001" RECODE_NODATA = "4002" RECODE_DATAEXIST = "4003" RECODE_DATAERR = "4004" RECODE_SESSIONERR = "4101" RECODE_LOGINERR = "4102" RECODE_PARAMERR = "4103" RECODE_USERERR = "4104" RECODE_ROLEERR = "4105" RECODE_PWDERR = "4106" RECODE_REQERR = "4201" RECODE_IPERR = "4202" RECODE_THIRDERR = "4301" RECODE_IOERR = "4302" RECODE_SERVERERR = "4500" RECODE_UNKNOWERR = "4501" ) var recodeText = map[string]string{ RECODE_OK: "成功", RECODE_DBERR: "数据库查询错误", RECODE_NODATA: "无数据", RECODE_DATAEXIST: "数据已存在", RECODE_DATAERR: "数据错误", RECODE_SESSIONERR: "用户未登录", RECODE_LOGINERR: "用户登录失败", RECODE_PARAMERR: "参数错误", RECODE_USERERR: "用户不存在或未激活", RECODE_ROLEERR: "用户身份错误", RECODE_PWDERR: "密码错误", RECODE_REQERR: "非法请求或请求次数受限", RECODE_IPERR: "IP受限", RECODE_THIRDERR: "第三方系统错误", RECODE_IOERR: "文件读写错误", RECODE_SERVERERR: "内部错误", RECODE_UNKNOWERR: "未知错误", } func RecodeText(code string) string { str, ok := recodeText[code] if ok { return str } return recodeText[RECODE_UNKNOWERR] }
//使用方式 func (this*TestController) Test(){ resp := make(map[string]interface{}) resp["errno"] =models.RECODE_DATAERR resp["errmsg"] = models.RecodeText(models.RECODE_DATAERR) this.RetData(resp) }