Make Status a type

Using a type is better than using an integer.
This commit is contained in:
Adnan Maolood
2021-02-20 16:15:26 -05:00
parent 99a8f09c22
commit 8938038797
6 changed files with 47 additions and 44 deletions

View File

@@ -38,19 +38,19 @@ func (f HandlerFunc) ServeGemini(ctx context.Context, w ResponseWriter, r *Reque
// RedirectHandler returns a request handler that redirects each request it
// receives to the given url using the given status code.
//
// The provided code should be in the 3x range and is usually
// The provided status code should be in the 3x range and is usually
// StatusRedirect or StatusPermanentRedirect.
func RedirectHandler(code int, url string) Handler {
return &redirectHandler{code, url}
func RedirectHandler(status Status, url string) Handler {
return &redirectHandler{status, url}
}
type redirectHandler struct {
code int
url string
status Status
url string
}
func (h *redirectHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *Request) {
w.WriteHeader(h.code, h.url)
w.WriteHeader(h.status, h.url)
}
// NotFound replies to the request with a Gemini 51 not found error.