code_string.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. *
  3. * Copyright 2017 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package codes
  19. import (
  20. "strconv"
  21. "google.golang.org/grpc/internal"
  22. )
  23. func init() {
  24. internal.CanonicalString = canonicalString
  25. }
  26. func (c Code) String() string {
  27. switch c {
  28. case OK:
  29. return "OK"
  30. case Canceled:
  31. return "Canceled"
  32. case Unknown:
  33. return "Unknown"
  34. case InvalidArgument:
  35. return "InvalidArgument"
  36. case DeadlineExceeded:
  37. return "DeadlineExceeded"
  38. case NotFound:
  39. return "NotFound"
  40. case AlreadyExists:
  41. return "AlreadyExists"
  42. case PermissionDenied:
  43. return "PermissionDenied"
  44. case ResourceExhausted:
  45. return "ResourceExhausted"
  46. case FailedPrecondition:
  47. return "FailedPrecondition"
  48. case Aborted:
  49. return "Aborted"
  50. case OutOfRange:
  51. return "OutOfRange"
  52. case Unimplemented:
  53. return "Unimplemented"
  54. case Internal:
  55. return "Internal"
  56. case Unavailable:
  57. return "Unavailable"
  58. case DataLoss:
  59. return "DataLoss"
  60. case Unauthenticated:
  61. return "Unauthenticated"
  62. default:
  63. return "Code(" + strconv.FormatInt(int64(c), 10) + ")"
  64. }
  65. }
  66. func canonicalString(c Code) string {
  67. switch c {
  68. case OK:
  69. return "OK"
  70. case Canceled:
  71. return "CANCELLED"
  72. case Unknown:
  73. return "UNKNOWN"
  74. case InvalidArgument:
  75. return "INVALID_ARGUMENT"
  76. case DeadlineExceeded:
  77. return "DEADLINE_EXCEEDED"
  78. case NotFound:
  79. return "NOT_FOUND"
  80. case AlreadyExists:
  81. return "ALREADY_EXISTS"
  82. case PermissionDenied:
  83. return "PERMISSION_DENIED"
  84. case ResourceExhausted:
  85. return "RESOURCE_EXHAUSTED"
  86. case FailedPrecondition:
  87. return "FAILED_PRECONDITION"
  88. case Aborted:
  89. return "ABORTED"
  90. case OutOfRange:
  91. return "OUT_OF_RANGE"
  92. case Unimplemented:
  93. return "UNIMPLEMENTED"
  94. case Internal:
  95. return "INTERNAL"
  96. case Unavailable:
  97. return "UNAVAILABLE"
  98. case DataLoss:
  99. return "DATA_LOSS"
  100. case Unauthenticated:
  101. return "UNAUTHENTICATED"
  102. default:
  103. return "CODE(" + strconv.FormatInt(int64(c), 10) + ")"
  104. }
  105. }