2020-10-28 00:21:33 +01:00
|
|
|
package gemini
|
|
|
|
|
2021-02-20 22:15:26 +01:00
|
|
|
// Status represents a Gemini status code.
|
|
|
|
type Status int
|
|
|
|
|
2021-02-14 22:23:38 +01:00
|
|
|
// Gemini status codes.
|
2020-10-28 00:21:33 +01:00
|
|
|
const (
|
2021-02-20 22:15:26 +01:00
|
|
|
StatusInput Status = 10
|
|
|
|
StatusSensitiveInput Status = 11
|
|
|
|
StatusSuccess Status = 20
|
|
|
|
StatusRedirect Status = 30
|
|
|
|
StatusPermanentRedirect Status = 31
|
|
|
|
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 00:21:33 +01:00
|
|
|
)
|
|
|
|
|
2021-02-20 22:15:26 +01:00
|
|
|
// Class returns the status class for the status code.
|
2021-02-14 22:23:38 +01:00
|
|
|
// 1x becomes 10, 2x becomes 20, and so on.
|
2021-02-20 22:15:26 +01:00
|
|
|
func (s Status) Class() Status {
|
|
|
|
return (s / 10) * 10
|
2020-10-28 00:21:33 +01:00
|
|
|
}
|
|
|
|
|
2021-02-20 22:15:26 +01:00
|
|
|
// String returns a text for the status code.
|
2021-02-17 18:06:22 +01:00
|
|
|
// It returns the empty string if the status code is unknown.
|
2021-02-20 22:15:26 +01:00
|
|
|
func (s Status) String() string {
|
|
|
|
switch s {
|
2021-02-17 18:06:22 +01:00
|
|
|
case StatusInput:
|
|
|
|
return "Input"
|
|
|
|
case StatusSensitiveInput:
|
|
|
|
return "Sensitive input"
|
|
|
|
case StatusSuccess:
|
|
|
|
return "Success"
|
|
|
|
case StatusRedirect:
|
2021-02-17 18:23:03 +01:00
|
|
|
return "Redirect"
|
2021-02-17 18:06:22 +01:00
|
|
|
case StatusPermanentRedirect:
|
|
|
|
return "Permanent redirect"
|
2020-10-28 00:21:33 +01:00
|
|
|
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 ""
|
|
|
|
}
|