12345678910111213141516171819202122232425262728293031 |
- package fserr
- import (
- "fmt"
- "git.sxidc.com/service-supports/fslog"
- "net/http"
- "sync"
- )
- var codeMap sync.Map
- var defaultErrCode = ErrCode{
- HttpCode: http.StatusOK,
- }
- func register(code ErrCode) {
- if _, ok := codeMap.Load(code.BusinessCode); ok {
- fslog.Warn(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
- }
|