code.go 625 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package code
  2. import (
  3. "sync"
  4. cherryCode "github.com/cherry-game/cherry/code"
  5. )
  6. const (
  7. emptyMsg = ""
  8. )
  9. var (
  10. lock = &sync.RWMutex{}
  11. dataCodeMaps = 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. dataCodeMaps[code] = message
  22. }
  23. func GetMessage(code int32) string {
  24. msg, found := dataCodeMaps[code]
  25. if found {
  26. return msg
  27. }
  28. return emptyMsg
  29. }
  30. func IsOK(code int32) bool {
  31. return cherryCode.IsOK(code)
  32. }
  33. func IsFail(code int32) bool {
  34. return cherryCode.IsFail(code)
  35. }