aboutsummaryrefslogtreecommitdiffstats
path: root/web/web.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-15 13:48:34 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-15 13:48:34 -0800
commit2327f93098b4278c93055a96224ae82cef60b083 (patch)
tree1a5e647bfa520c108dc7750e34332ad312572bdc /web/web.go
parent4c570c223e944a148dc81a4e1ee25d6ab524ae64 (diff)
downloadneko-2327f93098b4278c93055a96224ae82cef60b083.tar.gz
neko-2327f93098b4278c93055a96224ae82cef60b083.tar.bz2
neko-2327f93098b4278c93055a96224ae82cef60b083.zip
Backend: Fix linting issues, improve error handling, and replace magic numbers
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/web/web.go b/web/web.go
index b1a95d1..1f1bd62 100644
--- a/web/web.go
+++ b/web/web.go
@@ -98,7 +98,7 @@ func imageProxyHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("ETag", string(decodedURL))
w.Header().Set("Cache-Control", "public")
w.Header().Set("Expires", time.Now().Add(48*time.Hour).Format(time.RFC1123))
- w.Write(bts)
+ _, _ = w.Write(bts)
}
var AuthCookie = "auth"
@@ -126,7 +126,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
func logoutHandler(w http.ResponseWriter, r *http.Request) {
c := http.Cookie{Name: AuthCookie, MaxAge: 0, Path: "/", HttpOnly: true}
http.SetCookie(w, &c)
- fmt.Fprintf(w, "you are logged out")
+ _, _ = fmt.Fprintf(w, "you are logged out")
}
func Authenticated(r *http.Request) bool {
@@ -170,7 +170,7 @@ func serveBoxedFile(w http.ResponseWriter, r *http.Request, filename string) {
http.Error(w, "file not found", http.StatusNotFound)
return
}
- defer f.Close()
+ defer func() { _ = f.Close() }()
fi, _ := f.Stat()
http.ServeContent(w, r, filename, fi.ModTime(), f.(io.ReadSeeker))
@@ -188,7 +188,7 @@ func apiLoginHandler(w http.ResponseWriter, r *http.Request) {
c := http.Cookie{Name: AuthCookie, Value: "noauth", Path: "/", MaxAge: SecondsInAYear, HttpOnly: true}
http.SetCookie(w, &c)
w.Header().Set("Content-Type", "application/json")
- fmt.Fprintf(w, `{"status":"ok"}`)
+ _, _ = fmt.Fprintf(w, `{"status":"ok"}`)
return
}
@@ -200,7 +200,7 @@ func apiLoginHandler(w http.ResponseWriter, r *http.Request) {
c := http.Cookie{Name: AuthCookie, Value: string(v), Path: "/", MaxAge: SecondsInAYear, HttpOnly: true}
http.SetCookie(w, &c)
w.Header().Set("Content-Type", "application/json")
- fmt.Fprintf(w, `{"status":"ok"}`)
+ _, _ = fmt.Fprintf(w, `{"status":"ok"}`)
} else {
http.Error(w, `{"status":"error", "message":"bad login"}`, http.StatusUnauthorized)
}
@@ -209,10 +209,10 @@ func apiLoginHandler(w http.ResponseWriter, r *http.Request) {
func apiAuthStatusHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if Authenticated(r) {
- fmt.Fprintf(w, `{"status":"ok", "authenticated":true}`)
+ _, _ = fmt.Fprintf(w, `{"status":"ok", "authenticated":true}`)
} else {
w.WriteHeader(http.StatusUnauthorized)
- fmt.Fprintf(w, `{"status":"error", "authenticated":false}`)
+ _, _ = fmt.Fprintf(w, `{"status":"error", "authenticated":false}`)
}
}
@@ -311,7 +311,7 @@ func (w *gzipWriter) WriteHeader(status int) {
func (w *gzipWriter) Flush() {
if w.gz != nil {
- w.gz.Flush()
+ _ = w.gz.Flush()
}
if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
@@ -338,7 +338,7 @@ func GzipMiddleware(next http.Handler) http.Handler {
gzw := &gzipWriter{ResponseWriter: w}
next.ServeHTTP(gzw, r)
if gzw.gz != nil {
- gzw.gz.Close()
+ _ = gzw.gz.Close()
gzPool.Put(gzw.gz)
}
})
@@ -348,7 +348,7 @@ func apiLogoutHandler(w http.ResponseWriter, r *http.Request) {
c := http.Cookie{Name: AuthCookie, Value: "", Path: "/", MaxAge: -1, HttpOnly: true}
http.SetCookie(w, &c)
w.Header().Set("Content-Type", "application/json")
- fmt.Fprintf(w, `{"status":"ok"}`)
+ _, _ = fmt.Fprintf(w, `{"status":"ok"}`)
}
func generateRandomToken(n int) string {