2020-10-27 17:21:33 -06:00
|
|
|
package gemini
|
|
|
|
|
|
|
|
// Status codes.
|
|
|
|
const (
|
2021-02-09 07:41:36 -07:00
|
|
|
StatusInput = 10
|
|
|
|
StatusSensitiveInput = 11
|
|
|
|
StatusSuccess = 20
|
|
|
|
StatusRedirect = 30
|
|
|
|
StatusPermanentRedirect = 31
|
|
|
|
StatusTemporaryFailure = 40
|
|
|
|
StatusServerUnavailable = 41
|
|
|
|
StatusCGIError = 42
|
|
|
|
StatusProxyError = 43
|
|
|
|
StatusSlowDown = 44
|
|
|
|
StatusPermanentFailure = 50
|
|
|
|
StatusNotFound = 51
|
|
|
|
StatusGone = 52
|
|
|
|
StatusProxyRequestRefused = 53
|
|
|
|
StatusBadRequest = 59
|
|
|
|
StatusCertificateRequired = 60
|
|
|
|
StatusCertificateNotAuthorized = 61
|
|
|
|
StatusCertificateNotValid = 62
|
2020-10-27 17:21:33 -06:00
|
|
|
)
|
|
|
|
|
2020-10-28 11:40:25 -06:00
|
|
|
// Status code categories.
|
|
|
|
const (
|
2021-02-09 07:41:36 -07:00
|
|
|
StatusClassInput = 1
|
|
|
|
StatusClassSuccess = 2
|
|
|
|
StatusClassRedirect = 3
|
|
|
|
StatusClassTemporaryFailure = 4
|
|
|
|
StatusClassPermanentFailure = 5
|
|
|
|
StatusClassCertificateRequired = 6
|
2020-10-28 11:40:25 -06:00
|
|
|
)
|
|
|
|
|
2021-02-09 07:41:36 -07:00
|
|
|
// StatusClass returns the status class for this status code.
|
|
|
|
func StatusClass(status int) int {
|
|
|
|
return status / 10
|
2020-10-27 17:21:33 -06:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:10:57 -07:00
|
|
|
// Meta returns a description of the status code appropriate for use in a response.
|
|
|
|
//
|
|
|
|
// Meta returns an empty string for input, success, and redirect status codes.
|
2021-02-09 07:41:36 -07:00
|
|
|
func Meta(status int) string {
|
|
|
|
switch status {
|
2020-10-27 17:21:33 -06:00
|
|
|
case StatusTemporaryFailure:
|
2020-10-27 21:35:22 -06:00
|
|
|
return "Temporary failure"
|
2020-10-27 17:21:33 -06:00
|
|
|
case StatusServerUnavailable:
|
|
|
|
return "Server unavailable"
|
|
|
|
case StatusCGIError:
|
|
|
|
return "CGI error"
|
|
|
|
case StatusProxyError:
|
|
|
|
return "Proxy error"
|
|
|
|
case StatusSlowDown:
|
|
|
|
return "Slow down"
|
|
|
|
case StatusPermanentFailure:
|
2020-10-27 21:35:22 -06:00
|
|
|
return "Permanent failure"
|
2020-10-27 17:21:33 -06:00
|
|
|
case StatusNotFound:
|
|
|
|
return "Not found"
|
|
|
|
case StatusGone:
|
|
|
|
return "Gone"
|
|
|
|
case StatusProxyRequestRefused:
|
|
|
|
return "Proxy request refused"
|
|
|
|
case StatusBadRequest:
|
|
|
|
return "Bad request"
|
|
|
|
case StatusCertificateRequired:
|
|
|
|
return "Certificate required"
|
|
|
|
case StatusCertificateNotAuthorized:
|
|
|
|
return "Certificate not authorized"
|
|
|
|
case StatusCertificateNotValid:
|
|
|
|
return "Certificate not valid"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|