有些常量在golang在源代码中就已经定义,所以可以直接使用,不用在自己的代码里重复定义。

1.HTTP状态码

src/net/http/status.go

  1. const (
  2. StatusContinue = 100 // RFC 7231, 6.2.1
  3. StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2
  4. StatusProcessing = 102 // RFC 2518, 10.1
  5. StatusEarlyHints = 103 // RFC 8297
  6. StatusOK = 200 // RFC 7231, 6.3.1
  7. StatusCreated = 201 // RFC 7231, 6.3.2
  8. StatusAccepted = 202 // RFC 7231, 6.3.3
  9. StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4
  10. StatusNoContent = 204 // RFC 7231, 6.3.5
  11. StatusResetContent = 205 // RFC 7231, 6.3.6
  12. StatusPartialContent = 206 // RFC 7233, 4.1
  13. StatusMultiStatus = 207 // RFC 4918, 11.1
  14. StatusAlreadyReported = 208 // RFC 5842, 7.1
  15. StatusIMUsed = 226 // RFC 3229, 10.4.1
  16. StatusMultipleChoices = 300 // RFC 7231, 6.4.1
  17. StatusMovedPermanently = 301 // RFC 7231, 6.4.2
  18. StatusFound = 302 // RFC 7231, 6.4.3
  19. StatusSeeOther = 303 // RFC 7231, 6.4.4
  20. StatusNotModified = 304 // RFC 7232, 4.1
  21. StatusUseProxy = 305 // RFC 7231, 6.4.5
  22. _ = 306 // RFC 7231, 6.4.6 (Unused)
  23. StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7
  24. StatusPermanentRedirect = 308 // RFC 7538, 3
  25. StatusBadRequest = 400 // RFC 7231, 6.5.1
  26. StatusUnauthorized = 401 // RFC 7235, 3.1
  27. StatusPaymentRequired = 402 // RFC 7231, 6.5.2
  28. StatusForbidden = 403 // RFC 7231, 6.5.3
  29. StatusNotFound = 404 // RFC 7231, 6.5.4
  30. StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5
  31. StatusNotAcceptable = 406 // RFC 7231, 6.5.6
  32. StatusProxyAuthRequired = 407 // RFC 7235, 3.2
  33. StatusRequestTimeout = 408 // RFC 7231, 6.5.7
  34. StatusConflict = 409 // RFC 7231, 6.5.8
  35. StatusGone = 410 // RFC 7231, 6.5.9
  36. StatusLengthRequired = 411 // RFC 7231, 6.5.10
  37. StatusPreconditionFailed = 412 // RFC 7232, 4.2
  38. StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11
  39. StatusRequestURITooLong = 414 // RFC 7231, 6.5.12
  40. StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13
  41. StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4
  42. StatusExpectationFailed = 417 // RFC 7231, 6.5.14
  43. StatusTeapot = 418 // RFC 7168, 2.3.3
  44. StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2
  45. StatusUnprocessableEntity = 422 // RFC 4918, 11.2
  46. StatusLocked = 423 // RFC 4918, 11.3
  47. StatusFailedDependency = 424 // RFC 4918, 11.4
  48. StatusTooEarly = 425 // RFC 8470, 5.2.
  49. StatusUpgradeRequired = 426 // RFC 7231, 6.5.15
  50. StatusPreconditionRequired = 428 // RFC 6585, 3
  51. StatusTooManyRequests = 429 // RFC 6585, 4
  52. StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5
  53. StatusUnavailableForLegalReasons = 451 // RFC 7725, 3
  54. StatusInternalServerError = 500 // RFC 7231, 6.6.1
  55. StatusNotImplemented = 501 // RFC 7231, 6.6.2
  56. StatusBadGateway = 502 // RFC 7231, 6.6.3
  57. StatusServiceUnavailable = 503 // RFC 7231, 6.6.4
  58. StatusGatewayTimeout = 504 // RFC 7231, 6.6.5
  59. StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6
  60. StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1
  61. StatusInsufficientStorage = 507 // RFC 4918, 11.5
  62. StatusLoopDetected = 508 // RFC 5842, 7.2
  63. StatusNotExtended = 510 // RFC 2774, 7
  64. StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
  65. )

2.HTTP方法

src/net/http/method.go

  1. const (
  2. MethodGet = "GET"
  3. MethodHead = "HEAD"
  4. MethodPost = "POST"
  5. MethodPut = "PUT"
  6. MethodPatch = "PATCH" // RFC 5789
  7. MethodDelete = "DELETE"
  8. MethodConnect = "CONNECT"
  9. MethodOptions = "OPTIONS"
  10. MethodTrace = "TRACE"
  11. )

3.月份和星期字符串

src/time/time.go

  1. const (
  2. January Month = 1 + iota
  3. February
  4. March
  5. April
  6. May
  7. June
  8. July
  9. August
  10. September
  11. October
  12. November
  13. December
  14. )
  1. const (
  2. Sunday Weekday = iota
  3. Monday
  4. Tuesday
  5. Wednesday
  6. Thursday
  7. Friday
  8. Saturday
  9. )