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
}