summaryrefslogtreecommitdiff
path: root/internal/handler/handler.go
blob: bd8a2c19f8f1f0acd04c652f062807b6e4c7a3f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package handler

import (
	"net/http"
	"strings"

	"go.neonxp.dev/djson/internal/events"
)

func New(core Core, eventsDispatcher events.Dispatcher) *handler {
	return &handler{
		core:   core,
		events: eventsDispatcher,
	}
}

type handler struct {
	core   Core
	events events.Dispatcher
}

func writeError(code int, err error, w http.ResponseWriter) {
	_, _ = w.Write([]byte(err.Error()))
}

func parsePath(nodePath string) []string {
	arr := []string{}
	for _, v := range strings.Split(nodePath, "/") {
		if v != "" {
			arr = append(arr, v)
		}
	}
	return arr
}