File size: 4,042 Bytes
ca7217f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package errors

import (
	"net/http"
)

var statusCode = map[string]int{
	"Continue":            http.StatusContinue,
	"Switching Protocols": http.StatusSwitchingProtocols,
	"Processing":          http.StatusProcessing,
	"Early Hints":         http.StatusEarlyHints,

	"OK":                            http.StatusOK,
	"Created":                       http.StatusCreated,
	"Accepted":                      http.StatusAccepted,
	"Non-Authoritative Information": http.StatusNonAuthoritativeInfo,
	"No Content":                    http.StatusNoContent,
	"Reset Content":                 http.StatusResetContent,
	"Partial Content":               http.StatusPartialContent,
	"Multi-Status":                  http.StatusMultiStatus,
	"Already Reported":              http.StatusAlreadyReported,
	"IM Used":                       http.StatusIMUsed,

	"Multiple Choices":   http.StatusMultipleChoices,
	"Moved Permanently":  http.StatusMovedPermanently,
	"Found":              http.StatusFound,
	"See Other":          http.StatusSeeOther,
	"Not Modified":       http.StatusNotModified,
	"Use Proxy":          http.StatusUseProxy,
	"Temporary Redirect": http.StatusTemporaryRedirect,
	"Permanent Redirect": http.StatusPermanentRedirect,

	"Bad Request":                     http.StatusBadRequest,
	"Unauthorized":                    http.StatusUnauthorized,
	"Payment Required":                http.StatusPaymentRequired,
	"Forbidden":                       http.StatusForbidden,
	"Not Found":                       http.StatusNotFound,
	"Method Not Allowed":              http.StatusMethodNotAllowed,
	"Not Acceptable":                  http.StatusNotAcceptable,
	"Proxy Authentication Required":   http.StatusProxyAuthRequired,
	"Request Timeout":                 http.StatusRequestTimeout,
	"Conflict":                        http.StatusConflict,
	"Gone":                            http.StatusGone,
	"Length Required":                 http.StatusLengthRequired,
	"Precondition Failed":             http.StatusPreconditionFailed,
	"Request Entity Too Large":        http.StatusRequestEntityTooLarge,
	"Request URI Too Long":            http.StatusRequestURITooLong,
	"Unsupported Media Type":          http.StatusUnsupportedMediaType,
	"Requested Range Not Satisfiable": http.StatusRequestedRangeNotSatisfiable,
	"Expectation Failed":              http.StatusExpectationFailed,
	"I'm a teapot":                    http.StatusTeapot,
	"Misdirected Request":             http.StatusMisdirectedRequest,
	"Unprocessable Entity":            http.StatusUnprocessableEntity,
	"Locked":                          http.StatusLocked,
	"Failed Dependency":               http.StatusFailedDependency,
	"Too Early":                       http.StatusTooEarly,
	"Upgrade Required":                http.StatusUpgradeRequired,
	"Precondition Required":           http.StatusPreconditionRequired,
	"Too Many Requests":               http.StatusTooManyRequests,
	"Request Header Fields Too Large": http.StatusRequestHeaderFieldsTooLarge,
	"Unavailable For Legal Reasons":   http.StatusUnavailableForLegalReasons,

	"Internal Server Error":           http.StatusInternalServerError,
	"Not Implemented":                 http.StatusNotImplemented,
	"Bad Gateway":                     http.StatusBadGateway,
	"Service Unavailable":             http.StatusServiceUnavailable,
	"Gateway Timeout":                 http.StatusGatewayTimeout,
	"HTTP Version Not Supported":      http.StatusHTTPVersionNotSupported,
	"Variant Also Negotiates":         http.StatusVariantAlsoNegotiates,
	"Insufficient Storage":            http.StatusInsufficientStorage,
	"Loop Detected":                   http.StatusLoopDetected,
	"Not Extended":                    http.StatusNotExtended,
	"Network Authentication Required": http.StatusNetworkAuthenticationRequired,
}

// StatusCode is a reverse function of http.StatusText.
func StatusCode(text any) int {
	switch v := text.(type) {
	case string:
		return statusCode[v]
	case error:
		return statusCode[v.Error()]
	default:
		return 0
	}
}