aboutsummaryrefslogtreecommitdiff
path: root/status.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-20 16:15:26 -0500
committerAdnan Maolood <[email protected]>2021-02-20 16:16:32 -0500
commit893803879742057befabc4f6b5d4d412ac6612b6 (patch)
tree6d873d5645af6cbc4332f618e5950568bc1df486 /status.go
parentTimeoutHandler: Use provided context (diff)
downloadgo-gemini-893803879742057befabc4f6b5d4d412ac6612b6.tar.xz
go-gemini-893803879742057befabc4f6b5d4d412ac6612b6.zip
Make Status a type
Using a type is better than using an integer.
Diffstat (limited to 'status.go')
-rw-r--r--status.go51
1 files changed, 27 insertions, 24 deletions
diff --git a/status.go b/status.go
index 45eaed4..6e4f1bb 100644
--- a/status.go
+++ b/status.go
@@ -1,37 +1,40 @@
package gemini
+// Status represents a Gemini status code.
+type Status int
+
// Gemini status codes.
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
+ 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
)
-// StatusClass returns the status class for the provided status code.
+// Class returns the status class for the status code.
// 1x becomes 10, 2x becomes 20, and so on.
-func StatusClass(code int) int {
- return (code / 10) * 10
+func (s Status) Class() Status {
+ return (s / 10) * 10
}
-// StatusText returns a text for the provided status code.
+// String returns a text for the status code.
// It returns the empty string if the status code is unknown.
-func StatusText(code int) string {
- switch code {
+func (s Status) String() string {
+ switch s {
case StatusInput:
return "Input"
case StatusSensitiveInput: