package errCode import "fmt" // TODO 请在使用时手动添加 json 注解 type Error struct { code int32 msg string } var codes = map[int32]string{} func NewError(code int32, msg string) *Error { if _, ok := codes[code]; ok { panic(fmt.Sprintf("错误码 %d 已经存在,请更换一个", code)) } codes[code] = msg return &Error{code: code, msg: msg} } func (e *Error) Code() int32 { return e.code } func (e *Error) Msg() string { return e.msg }