有些常量在golang在源代码中就已经定义,所以可以直接使用,不用在自己的代码里重复定义。
1.HTTP状态码
src/net/http/status.go
const (StatusContinue = 100 // RFC 7231, 6.2.1StatusSwitchingProtocols = 101 // RFC 7231, 6.2.2StatusProcessing = 102 // RFC 2518, 10.1StatusEarlyHints = 103 // RFC 8297StatusOK = 200 // RFC 7231, 6.3.1StatusCreated = 201 // RFC 7231, 6.3.2StatusAccepted = 202 // RFC 7231, 6.3.3StatusNonAuthoritativeInfo = 203 // RFC 7231, 6.3.4StatusNoContent = 204 // RFC 7231, 6.3.5StatusResetContent = 205 // RFC 7231, 6.3.6StatusPartialContent = 206 // RFC 7233, 4.1StatusMultiStatus = 207 // RFC 4918, 11.1StatusAlreadyReported = 208 // RFC 5842, 7.1StatusIMUsed = 226 // RFC 3229, 10.4.1StatusMultipleChoices = 300 // RFC 7231, 6.4.1StatusMovedPermanently = 301 // RFC 7231, 6.4.2StatusFound = 302 // RFC 7231, 6.4.3StatusSeeOther = 303 // RFC 7231, 6.4.4StatusNotModified = 304 // RFC 7232, 4.1StatusUseProxy = 305 // RFC 7231, 6.4.5_ = 306 // RFC 7231, 6.4.6 (Unused)StatusTemporaryRedirect = 307 // RFC 7231, 6.4.7StatusPermanentRedirect = 308 // RFC 7538, 3StatusBadRequest = 400 // RFC 7231, 6.5.1StatusUnauthorized = 401 // RFC 7235, 3.1StatusPaymentRequired = 402 // RFC 7231, 6.5.2StatusForbidden = 403 // RFC 7231, 6.5.3StatusNotFound = 404 // RFC 7231, 6.5.4StatusMethodNotAllowed = 405 // RFC 7231, 6.5.5StatusNotAcceptable = 406 // RFC 7231, 6.5.6StatusProxyAuthRequired = 407 // RFC 7235, 3.2StatusRequestTimeout = 408 // RFC 7231, 6.5.7StatusConflict = 409 // RFC 7231, 6.5.8StatusGone = 410 // RFC 7231, 6.5.9StatusLengthRequired = 411 // RFC 7231, 6.5.10StatusPreconditionFailed = 412 // RFC 7232, 4.2StatusRequestEntityTooLarge = 413 // RFC 7231, 6.5.11StatusRequestURITooLong = 414 // RFC 7231, 6.5.12StatusUnsupportedMediaType = 415 // RFC 7231, 6.5.13StatusRequestedRangeNotSatisfiable = 416 // RFC 7233, 4.4StatusExpectationFailed = 417 // RFC 7231, 6.5.14StatusTeapot = 418 // RFC 7168, 2.3.3StatusMisdirectedRequest = 421 // RFC 7540, 9.1.2StatusUnprocessableEntity = 422 // RFC 4918, 11.2StatusLocked = 423 // RFC 4918, 11.3StatusFailedDependency = 424 // RFC 4918, 11.4StatusTooEarly = 425 // RFC 8470, 5.2.StatusUpgradeRequired = 426 // RFC 7231, 6.5.15StatusPreconditionRequired = 428 // RFC 6585, 3StatusTooManyRequests = 429 // RFC 6585, 4StatusRequestHeaderFieldsTooLarge = 431 // RFC 6585, 5StatusUnavailableForLegalReasons = 451 // RFC 7725, 3StatusInternalServerError = 500 // RFC 7231, 6.6.1StatusNotImplemented = 501 // RFC 7231, 6.6.2StatusBadGateway = 502 // RFC 7231, 6.6.3StatusServiceUnavailable = 503 // RFC 7231, 6.6.4StatusGatewayTimeout = 504 // RFC 7231, 6.6.5StatusHTTPVersionNotSupported = 505 // RFC 7231, 6.6.6StatusVariantAlsoNegotiates = 506 // RFC 2295, 8.1StatusInsufficientStorage = 507 // RFC 4918, 11.5StatusLoopDetected = 508 // RFC 5842, 7.2StatusNotExtended = 510 // RFC 2774, 7StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6)
2.HTTP方法
src/net/http/method.go
const (MethodGet = "GET"MethodHead = "HEAD"MethodPost = "POST"MethodPut = "PUT"MethodPatch = "PATCH" // RFC 5789MethodDelete = "DELETE"MethodConnect = "CONNECT"MethodOptions = "OPTIONS"MethodTrace = "TRACE")
3.月份和星期字符串
src/time/time.go
const (January Month = 1 + iotaFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember)
const (Sunday Weekday = iotaMondayTuesdayWednesdayThursdayFridaySaturday)
