mirror of
https://codeberg.org/scip/anydb.git
synced 2026-10-08 11:14:20 +02:00
update linter config, satisfy linter (#28)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user