center.go 654 B

1234567891011121314151617181920212223242526272829303132333435
  1. package fserr
  2. import (
  3. "git.sxidc.com/service-supports/fslog"
  4. "github.com/puzpuzpuz/xsync"
  5. )
  6. var codeMap *xsync.MapOf[int, ErrCode]
  7. var defaultErrCode = ErrCode{
  8. HttpCode: 200,
  9. }
  10. func init() {
  11. codeMap = xsync.NewIntegerMapOf[int, ErrCode]()
  12. }
  13. func register(code ErrCode) {
  14. if _, ok := codeMap.Load(code.BusinessCode); ok {
  15. fslog.With("code", code.BusinessCode).
  16. With("message", code.Message).
  17. Warn("duplicate business code")
  18. }
  19. codeMap.Store(code.BusinessCode, code)
  20. }
  21. func getCode(business int) ErrCode {
  22. code, ok := codeMap.Load(business)
  23. if ok {
  24. return code
  25. }
  26. ret := defaultErrCode
  27. ret.BusinessCode = business
  28. return ret
  29. }