ConstAndEnum.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package zsshrpc_server
  2. const (
  3. SvrLogLevel_DEBUG = 0
  4. SvrLogLevel_INFO = 1
  5. SvrLogLevel_WARNING = 2
  6. SvrLogLevel_ERROR = 3
  7. )
  8. type ZSshRpcChState int8
  9. const (
  10. ChannelState_IDLE ZSshRpcChState = 0
  11. ChannelState_WAIT_URI ZSshRpcChState = 1
  12. ChannelState_WAIT_JSON ZSshRpcChState = 2
  13. ChannelState_EXEC_HANDLER ZSshRpcChState = 3
  14. ChannelState_WAIT_JSON_READ ZSshRpcChState = 4
  15. )
  16. type ZSshRpcMethod int8
  17. const (
  18. RpcMethod_CALL ZSshRpcMethod = 0
  19. RpcMethod_ADD ZSshRpcMethod = 1
  20. RpcMethod_DEL ZSshRpcMethod = 2
  21. RpcMethod_GET ZSshRpcMethod = 3
  22. RpcMethod_SET ZSshRpcMethod = 4
  23. )
  24. const (
  25. ResponseStatusCode_OK = 200
  26. ResponseStatusCode_NO_CONTENT = 204
  27. ResponseStatusCode_METHOD_NOT_ALLOWED = 405
  28. ResponseStatusCode_NOT_FOUND = 404
  29. ResponseStatusCode_FORBIDDEN = 403
  30. ResponseStatusCode_INVALID_REQUEST = 400
  31. ResponseStatusCode_INTERNAL_ERROR = 500
  32. ResponseStatusCode_VERSION_NOT_SUPPORT = 505
  33. ResponseStatusCode_UNKNOWN = 600
  34. ResponseStatusCode_JSON_DECODE_ERROR = 601
  35. )
  36. func GetResponseStatusCodeString(code int) string {
  37. switch code {
  38. case 200:
  39. return "OK"
  40. case 204:
  41. return "NO_CONTENT"
  42. case 405:
  43. return "METHOD_NOT_ALLOWED"
  44. case 404:
  45. return "NOT_FOUND"
  46. case 403:
  47. return "FORBIDDEN"
  48. case 400:
  49. return "INVALID_REQUEST"
  50. case 500:
  51. return "INTERNAL_ERROR"
  52. case 505:
  53. return "VERSION_NOT_SUPPORT"
  54. case 601:
  55. return "JSON_DECODE_ERROR"
  56. default:
  57. return "UNKNOWN"
  58. }
  59. }
  60. func GetOperationMethodName(method ZSshRpcMethod) string {
  61. switch method {
  62. case RpcMethod_CALL:
  63. return "CALL"
  64. case RpcMethod_ADD:
  65. return "ADD"
  66. case RpcMethod_DEL:
  67. return "DEL"
  68. case RpcMethod_GET:
  69. return "GET"
  70. case RpcMethod_SET:
  71. return "SET"
  72. default:
  73. return "UNKNOWN"
  74. }
  75. }