2020-10-28 00:21:33 +01:00
|
|
|
package gemini
|
|
|
|
|
|
|
|
// Status codes.
|
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
|
|
|
StatusInput Status = 10
|
|
|
|
StatusSensitiveInput Status = 11
|
|
|
|
StatusSuccess Status = 20
|
|
|
|
StatusRedirect Status = 30
|
2020-10-31 21:51:10 +01:00
|
|
|
StatusPermanentRedirect Status = 31
|
2020-10-28 00:21:33 +01:00
|
|
|
StatusTemporaryFailure Status = 40
|
|
|
|
StatusServerUnavailable Status = 41
|
|
|
|
StatusCGIError Status = 42
|
|
|
|
StatusProxyError Status = 43
|
|
|
|
StatusSlowDown Status = 44
|
|
|
|
StatusPermanentFailure Status = 50
|
|
|
|
StatusNotFound Status = 51
|
|
|
|
StatusGone Status = 52
|
|
|
|
StatusProxyRequestRefused Status = 53
|
|
|
|
StatusBadRequest Status = 59
|
|
|
|
StatusCertificateRequired Status = 60
|
|
|
|
StatusCertificateNotAuthorized Status = 61
|
|
|
|
StatusCertificateNotValid Status = 62
|
|
|
|
)
|
|
|
|
|
2020-10-28 18:40:25 +01:00
|
|
|
// Status code categories.
|
|
|
|
type StatusClass int
|
|
|
|
|
|
|
|
const (
|
|
|
|
StatusClassInput StatusClass = 1
|
|
|
|
StatusClassSuccess StatusClass = 2
|
|
|
|
StatusClassRedirect StatusClass = 3
|
|
|
|
StatusClassTemporaryFailure StatusClass = 4
|
|
|
|
StatusClassPermanentFailure StatusClass = 5
|
|
|
|
StatusClassCertificateRequired StatusClass = 6
|
|
|
|
)
|
|
|
|
|
2020-10-28 00:21:33 +01:00
|
|
|
// Class returns the status class for this status code.
|
|
|
|
func (s Status) Class() StatusClass {
|
|
|
|
return StatusClass(s / 10)
|
|
|
|
}
|
|
|
|
|
2021-01-10 06:10:57 +01: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.
|
|
|
|
func (s Status) Meta() string {
|
2020-10-28 00:21:33 +01:00
|
|
|
switch s {
|
|
|
|
case StatusTemporaryFailure:
|
2020-10-28 04:35:22 +01:00
|
|
|
return "Temporary failure"
|
2020-10-28 00:21:33 +01: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-28 04:35:22 +01:00
|
|
|
return "Permanent failure"
|
2020-10-28 00:21:33 +01: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 ""
|
|
|
|
}
|