update linter config, satisfy linter (#28)

This commit is contained in:
T. von Dein
2026-08-31 22:06:25 +02:00
parent 5c9900d985
commit 1d45b2c6fe
24 changed files with 331 additions and 221 deletions

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package rest
import (
//"github.com/alecthomas/repr"
// "github.com/alecthomas/repr"
"encoding/json"
"log"
@@ -28,7 +28,7 @@ import (
)
type SetContext struct {
Query string `json:"query" form:"query"`
Query string `form:"query" json:"query"`
}
type ListResponse struct {
@@ -50,6 +50,7 @@ func RestList(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
if err != nil {
if err.Error() != `EOF` {
http.Error(resp, err.Error(), http.StatusBadRequest)
return
}
}
@@ -58,6 +59,7 @@ func RestList(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
entries, err := conf.DB.List(attr, attr.Fulltext)
if err != nil {
JsonStatus(resp, http.StatusForbidden, "Unable to list keys: "+err.Error())
return
}
@@ -69,7 +71,6 @@ func RestList(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
Success: true,
Entries: entries,
})
if err != nil {
log.Fatal(err)
}
@@ -78,6 +79,7 @@ func RestList(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) {
if key == "" {
JsonStatus(resp, http.StatusForbidden, "key not provided")
return
}
@@ -85,10 +87,13 @@ func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.
entry, err := conf.DB.Get(&app.DbAttr{Key: key})
if err != nil {
JsonStatus(resp, http.StatusForbidden, "Unable to get key: "+err.Error())
return
}
if entry.Key == "" {
if entry.GetKey() == "" {
JsonStatus(resp, http.StatusForbidden, "Key does not exist")
return
}
@@ -100,7 +105,6 @@ func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.
Success: true,
Entry: entry,
})
if err != nil {
log.Fatal(err)
}
@@ -109,6 +113,7 @@ func RestGet(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.
func RestDelete(resp http.ResponseWriter, req *http.Request, key string, conf *cfg.Config) {
if key == "" {
JsonStatus(resp, http.StatusForbidden, "key not provided")
return
}
@@ -116,6 +121,7 @@ func RestDelete(resp http.ResponseWriter, req *http.Request, key string, conf *c
err := conf.DB.Del(&app.DbAttr{Key: key})
if err != nil {
JsonStatus(resp, http.StatusForbidden, "Unable to delete key: "+err.Error())
return
}
@@ -128,6 +134,7 @@ func RestSet(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
err := json.NewDecoder(req.Body).Decode(&attr)
if err != nil {
http.Error(resp, err.Error(), http.StatusBadRequest)
return
}
@@ -141,6 +148,7 @@ func RestSet(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
err = conf.DB.Set(attr)
if err != nil {
JsonStatus(resp, http.StatusForbidden, "Unable to set key: "+err.Error())
return
}

View File

@@ -1,3 +1,5 @@
package rest
/*
This logging middleware is based on
@@ -7,7 +9,6 @@ https://github.com/elithrar/admission-control/blob/v0.6.3/request_logger.go
I am using slog and added a couple of small modifications.
*/
package rest
import (
"log/slog"
@@ -20,6 +21,7 @@ import (
// written HTTP status code to be captured for logging.
type responseWriter struct {
http.ResponseWriter
status int
size int
wroteHeader bool
@@ -48,7 +50,6 @@ func (rw *responseWriter) WriteHeader(code int) {
}
func (rw *responseWriter) Write(data []byte) (int, error) {
written, err := rw.ResponseWriter.Write(data)
rw.size += written
@@ -75,7 +76,9 @@ func LogHandler() func(http.Handler) http.Handler {
next.ServeHTTP(wrapped, req)
header := wrapped.Header()["Content-Type"]
contenttype := ""
var contenttype string
if header == nil {
contenttype = "text/plain"
} else {

View File

@@ -85,7 +85,6 @@ func JsonStatus(resp http.ResponseWriter, code int, msg string) {
Message: msg,
Success: success,
})
if err != nil {
log.Fatal(err)
}