code_msg.go 599 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package code
  2. import (
  3. mhayaCode "github.com/mhaya/code"
  4. "sync"
  5. )
  6. const (
  7. emptyMsg = ""
  8. )
  9. var (
  10. lock = &sync.RWMutex{}
  11. resultMaps = make(map[int32]string)
  12. )
  13. func AddAll(maps map[int32]string) {
  14. for k, v := range maps {
  15. Add(k, v)
  16. }
  17. }
  18. func Add(code int32, message string) {
  19. lock.Lock()
  20. defer lock.Unlock()
  21. resultMaps[code] = message
  22. }
  23. func GetMessage(code int32) string {
  24. msg, found := resultMaps[code]
  25. if found {
  26. return msg
  27. }
  28. return emptyMsg
  29. }
  30. func IsOK(code int32) bool {
  31. return mhayaCode.IsOK(code)
  32. }
  33. func IsFail(code int32) bool {
  34. return mhayaCode.IsFail(code)
  35. }