package fserr import ( "fmt" "net/http" "sync" ) var codeMap sync.Map var defaultErrCode = ErrCode{ HttpCode: http.StatusOK, } func register(code ErrCode) { if _, ok := codeMap.Load(code.BusinessCode); ok { panic(fmt.Sprintf("duplicate business code, code: %d, message: %s", code.BusinessCode, code.Message)) } codeMap.Store(code.BusinessCode, code) } func getCode(business int) ErrCode { code, ok := codeMap.Load(business) if ok { return code.(ErrCode) } ret := defaultErrCode ret.BusinessCode = business return ret }