diff options
Diffstat (limited to 'internal/handler/handler.go')
-rw-r--r-- | internal/handler/handler.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/handler/handler.go b/internal/handler/handler.go new file mode 100644 index 0000000..11c1936 --- /dev/null +++ b/internal/handler/handler.go @@ -0,0 +1,39 @@ +package handler + +import ( + "net/http" + "strings" + + "go.neonxp.dev/json" + jsonModel "go.neonxp.dev/json/model" + + "go.neonxp.dev/djson/internal/events" + "go.neonxp.dev/djson/internal/tree" +) + +func New(core tree.Core, eventsDispatcher events.Dispatcher) Handler { + return &handler{ + core: core, + events: eventsDispatcher, + } +} + +type handler struct { + core tree.Core + events events.Dispatcher +} + +func writeError(code int, err error, w http.ResponseWriter) { + jsonErr, _ := json.Marshal(jsonModel.NewNode(err.Error())) + _, _ = w.Write(jsonErr) +} + +func parsePath(nodePath string) []string { + arr := []string{} + for _, v := range strings.Split(nodePath, "/") { + if v != "" { + arr = append(arr, v) + } + } + return arr +} |