mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
JSON parser
This commit is contained in:
parent
bbbd27a3a6
commit
13da696927
2 changed files with 80 additions and 0 deletions
33
handler.go
33
handler.go
|
|
@ -115,6 +115,7 @@ func NewRouter(handler *Handler) *mux.Router {
|
|||
router.HandleFunc("/index/{index}/frame/{frame}/restore", handler.handlePostFrameRestore).Methods("POST")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/time-quantum", handler.handlePatchFrameTimeQuantum).Methods("PATCH")
|
||||
router.HandleFunc("/index/{index}/frame/{frame}/views", handler.handleGetFrameViews).Methods("GET")
|
||||
router.HandleFunc("/index/{index}/input/{input-definition}", handler.handlePostInput).Methods("POST")
|
||||
router.HandleFunc("/index/{index}/input-definition/{input-definition}", handler.handleGetInputDefinition).Methods("GET")
|
||||
router.HandleFunc("/index/{index}/input-definition/{input-definition}", handler.handlePostInputDefinition).Methods("POST")
|
||||
router.HandleFunc("/index/{index}/input-definition/{input-definition}", handler.handleDeleteInputDefinition).Methods("DELETE")
|
||||
|
|
@ -1518,6 +1519,7 @@ func (h *Handler) handlePostInputDefinition(w http.ResponseWriter, r *http.Reque
|
|||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
// Encode InputDefinition to its internal representation.
|
||||
def, err := req.Encode()
|
||||
|
|
@ -1622,3 +1624,34 @@ func (h *Handler) handleDeleteInputDefinition(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
type defaultInputDefinitionResponse struct{}
|
||||
|
||||
func (h *Handler) handlePostInput(w http.ResponseWriter, r *http.Request) {
|
||||
indexName := mux.Vars(r)["index"]
|
||||
inputDefName := mux.Vars(r)["input-definition"]
|
||||
|
||||
// Find index.
|
||||
index := h.Holder.Index(indexName)
|
||||
if index == nil {
|
||||
http.Error(w, ErrIndexNotFound.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Decode request.
|
||||
var reqs []interface{}
|
||||
err := json.NewDecoder(r.Body).Decode(&reqs)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
for _, req := range reqs {
|
||||
definition := index.inputDefinition(inputDefName)
|
||||
err = index.JSONParser(req.(map[string]interface{}), definition)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
47
index.go
47
index.go
|
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pilosa/pilosa/internal"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Default index settings.
|
||||
|
|
@ -755,3 +756,49 @@ func (i *Index) openInputDefinition() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func (i *Index) JSONParser(req map[string]interface{}, inputDef *InputDefinition) error {
|
||||
fmt.Println(i.Frames)
|
||||
for _, field := range inputDef.fields{
|
||||
if _, ok := req[field.Name]; !ok {
|
||||
return fmt.Errorf("field not found")
|
||||
}
|
||||
for _, action := range field.Actions {
|
||||
switch action.ValueDestination {
|
||||
case "map":
|
||||
err := i.MapAction(action.Frame, action.ValueMap, req[field.Name].(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error map value: %s", err)
|
||||
}
|
||||
case "stringToBool":
|
||||
fmt.Println("HERE")
|
||||
err := i.StringToBool(action.Frame, action.RowID, req[field.Name].(bool))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error map value: %s", err)
|
||||
}
|
||||
case "valueToRow":
|
||||
err := i.ValueToRow(action.Frame, field.Name, req[field.Name].(uint64))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error map value: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val := reflect.ValueOf(Action{})
|
||||
for i := 0; i < val.Type().NumField(); i++{
|
||||
fmt.Println(val.Type().Field(i).Type)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (i *Index) MapAction(frame string, valueMap map[string]uint64, value string) error{
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Index) StringToBool(frame string, rowID uint64, value bool) error{
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Index) ValueToRow(frame, name string, value uint64) error{
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue