center.go 586 B

12345678910111213141516171819202122232425262728293031
  1. package fserr
  2. import (
  3. "fmt"
  4. "git.sxidc.com/service-supports/fslog"
  5. "net/http"
  6. "sync"
  7. )
  8. var codeMap sync.Map
  9. var defaultErrCode = ErrCode{
  10. HttpCode: http.StatusOK,
  11. }
  12. func register(code ErrCode) {
  13. if _, ok := codeMap.Load(code.BusinessCode); ok {
  14. fslog.Warn(fmt.Sprintf("duplicate business code, code: %d, message: %s", code.BusinessCode, code.Message))
  15. }
  16. codeMap.Store(code.BusinessCode, code)
  17. }
  18. func getCode(business int) ErrCode {
  19. code, ok := codeMap.Load(business)
  20. if ok {
  21. return code.(ErrCode)
  22. }
  23. ret := defaultErrCode
  24. ret.BusinessCode = business
  25. return ret
  26. }