fix liniting bugs

This commit is contained in:
2025-12-23 14:30:37 +01:00
parent b4fa28d0c5
commit 38d3d2c442
3 changed files with 12 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import (
//"github.com/alecthomas/repr" //"github.com/alecthomas/repr"
"encoding/json" "encoding/json"
"log"
"net/http" "net/http"
"codeberg.org/scip/anydb/app" "codeberg.org/scip/anydb/app"
@@ -62,12 +63,16 @@ func RestList(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Type", "application/json")
json.NewEncoder(resp).Encode( err = json.NewEncoder(resp).Encode(
ListResponse{ ListResponse{
Code: http.StatusOK, Code: http.StatusOK,
Success: true, Success: true,
Entries: entries, Entries: entries,
}) })
if err != nil {
log.Fatal(err)
}
} }
func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) { func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) {
@@ -89,12 +94,16 @@ func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.
resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Type", "application/json")
json.NewEncoder(resp).Encode( err = json.NewEncoder(resp).Encode(
SingleResponse{ SingleResponse{
Code: http.StatusOK, Code: http.StatusOK,
Success: true, Success: true,
Entry: entry, Entry: entry,
}) })
if err != nil {
log.Fatal(err)
}
} }
func RestDelete(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) { func RestDelete(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) {

View File

@@ -45,8 +45,6 @@ func (rw *responseWriter) WriteHeader(code int) {
rw.status = code rw.status = code
rw.ResponseWriter.WriteHeader(code) rw.ResponseWriter.WriteHeader(code)
rw.wroteHeader = true rw.wroteHeader = true
return
} }
func (rw *responseWriter) Write(data []byte) (int, error) { func (rw *responseWriter) Write(data []byte) (int, error) {

View File

@@ -72,7 +72,7 @@ func Runserver(conf *cfg.Config, args []string) error {
Wrapper to respond with proper json status, message and code, Wrapper to respond with proper json status, message and code,
shall be prepared and called by the handlers directly. shall be prepared and called by the handlers directly.
*/ */
func JsonStatus(resp http.ResponseWriter, code int, msg string) error { func JsonStatus(resp http.ResponseWriter, code int, msg string) {
success := code == http.StatusOK success := code == http.StatusOK
resp.Header().Set("Content-Type", "application/json") resp.Header().Set("Content-Type", "application/json")
@@ -84,6 +84,4 @@ func JsonStatus(resp http.ResponseWriter, code int, msg string) error {
Message: msg, Message: msg,
Success: success, Success: success,
}) })
return nil
} }