package common const ( ServiceError = iota + 100 ParamError Expired ) var codeMap = map[int]string{ ServiceError: "系统错误", ParamError: "参数错误", Expired: "账户已过期", } type err struct { code int msg string } type PpError interface { Error() string Code() int } func (error *err) Error() string { return error.msg } func (error *err) Code() int { return error.code } func New(code int) error { msg := codeMap[code] if msg == "" { msg = "unknown" } err := &err{ code: code, msg: msg, } return err }