Impl delete find filters for boltdb
This commit is contained in:
49
view/httpisnow.go
Normal file
49
view/httpisnow.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"local/dndex/storage"
|
||||
"local/dndex/storage/entity"
|
||||
"local/dndex/storage/operator"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
)
|
||||
|
||||
func httpisnow(g storage.Graph, w http.ResponseWriter, r *http.Request) error {
|
||||
namespace := path.Base(r.URL.Path)
|
||||
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name, err := jsonparser.GetString(b, entity.JSONName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot find %q: %v", entity.JSONName, err)
|
||||
}
|
||||
if name == "" {
|
||||
http.Error(w, `{"error":"must provide a name"}`, http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
|
||||
key, err := jsonparser.GetString(b, "set", "key")
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot find %q: %v", "set.key", err)
|
||||
}
|
||||
if key == "" {
|
||||
http.Error(w, `{"error":"must provide a set.key"}`, http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
|
||||
value, err := jsonparser.GetString(b, "set", "value")
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot find %q: %v", "set.value", err)
|
||||
}
|
||||
|
||||
operator := operator.Set{Key: key, Value: value}
|
||||
|
||||
return g.Update(r.Context(), namespace, entity.One{Name: name}, operator)
|
||||
}
|
||||
Reference in New Issue
Block a user