go-gemini/status.go

74 lines
2.0 KiB
Go
Raw Normal View History

2020-10-27 23:21:33 +00:00
package gemini
2021-02-14 21:23:38 +00:00
// Gemini status codes.
2020-10-27 23:21:33 +00:00
const (
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 23:21:33 +00:00
)
2021-02-17 17:23:03 +00:00
// StatusClass returns the status class for the provided status code.
2021-02-14 21:23:38 +00:00
// 1x becomes 10, 2x becomes 20, and so on.
2021-02-17 17:23:03 +00:00
func StatusClass(code int) int {
return (code / 10) * 10
2020-10-27 23:21:33 +00:00
}
// StatusText returns a text for the provided status code.
// It returns the empty string if the status code is unknown.
2021-02-17 17:23:03 +00:00
func StatusText(code int) string {
switch code {
case StatusInput:
return "Input"
case StatusSensitiveInput:
return "Sensitive input"
case StatusSuccess:
return "Success"
case StatusRedirect:
2021-02-17 17:23:03 +00:00
return "Redirect"
case StatusPermanentRedirect:
return "Permanent redirect"
2020-10-27 23:21:33 +00:00
case StatusTemporaryFailure:
2020-10-28 03:35:22 +00:00
return "Temporary failure"
2020-10-27 23:21:33 +00: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 03:35:22 +00:00
return "Permanent failure"
2020-10-27 23:21:33 +00: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 ""
}