diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-05 19:26:29 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-05 19:26:29 +0200 |
commit | 5168a9476f0e83264ecafc85bc9145e8bdcbb8dc (patch) | |
tree | 5cd04e84f8aa427d274e16dd8cf507ff48468e07 /pkg/ext/responses.go | |
parent | 24c121a9ef229870f54de487de01c15a15ebbff1 (diff) | |
download | lens-5168a9476f0e83264ecafc85bc9145e8bdcbb8dc.tar.gz lens-5168a9476f0e83264ecafc85bc9145e8bdcbb8dc.tar.bz2 lens-5168a9476f0e83264ecafc85bc9145e8bdcbb8dc.zip |
ref: Move net/http
I was young and naive, fasthttp does not fit my needs and make
development slower. I'll move to net/http since it has a wider support
and will spare some time on implementation detail things (like CSRF). It
will allow me to reduce a bit of the code since there may be lib for
handling cookie encryption and auth in general.
Diffstat (limited to 'pkg/ext/responses.go')
-rw-r--r-- | pkg/ext/responses.go | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/pkg/ext/responses.go b/pkg/ext/responses.go index dbad5b2..ba58dd5 100644 --- a/pkg/ext/responses.go +++ b/pkg/ext/responses.go @@ -1,39 +1,21 @@ package ext import ( - "bytes" "fmt" - - "github.com/valyala/fasthttp" + "net/http" "git.sr.ht/~gabrielgio/img/templates" ) -var ( - ContentTypeHTML = []byte("text/html") -) - -func NotFoundHTML(ctx *fasthttp.RequestCtx) { - templates.WritePageTemplate(ctx, &templates.ErrorPage{ +func NotFound(w http.ResponseWriter, r *http.Request) { + templates.WritePageTemplate(w, &templates.ErrorPage{ Err: "Not Found", }) } -func NotFound(ctx *fasthttp.RequestCtx) { - ctx.Response.SetStatusCode(404) - ct := ctx.Response.Header.ContentType() - if bytes.Equal(ct, ContentTypeHTML) { - NotFoundHTML(ctx) - } -} - -func InternalServerError(ctx *fasthttp.RequestCtx, err error) { - ctx.Response.SetStatusCode(500) - templates.WritePageTemplate(ctx, &templates.ErrorPage{ +func InternalServerError(w http.ResponseWriter, err error) { + w.WriteHeader(http.StatusInternalServerError) + templates.WritePageTemplate(w, &templates.ErrorPage{ Err: fmt.Sprintf("Internal Server Error:\n%s", err.Error()), }) } - -func NoContent(ctx *fasthttp.RequestCtx) { - ctx.Response.SetStatusCode(204) -} |