-
Notifications
You must be signed in to change notification settings - Fork 84
/
api.go
43 lines (35 loc) · 1.45 KB
/
api.go
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
35
36
37
38
39
40
41
42
43
package core
import (
"net/http"
"github.com/gorilla/mux"
"github.com/markbates/pkger"
"github.com/netgusto/nodebook/src/core/httphandler"
"github.com/netgusto/nodebook/src/core/shared/service"
)
func makeAPI(
nbRegistry *service.NotebookRegistry,
recipeRegistry *service.RecipeRegistry,
routes *service.Routes,
csrfService *service.CSRFService,
useDocker bool,
) *mux.Router {
fs := http.FileServer(pkger.Dir("/dist/frontend/"))
root := mux.NewRouter()
root.Path("/").HandlerFunc(httphandler.HomePageHandler(nbRegistry, recipeRegistry, routes))
root.Path("/csrf").HandlerFunc(httphandler.CsrfHandler(csrfService))
root.Path("/notebook/{name:.+}").HandlerFunc(httphandler.NotebookHandler(nbRegistry, routes))
api := root.Methods("post").PathPrefix("/api").Subrouter()
api.Path("/notebook/new").HandlerFunc(httphandler.ApiNewNotebookHandler(
nbRegistry,
recipeRegistry,
csrfService,
routes,
nbRegistry.GetNotebooksPath(),
))
api.Path("/notebook/{name:.+}/rename").HandlerFunc(httphandler.ApiNotebookRenameHandler(nbRegistry, csrfService, routes))
api.Path("/notebook/{name:.+}/setcontent").HandlerFunc(httphandler.ApiNotebookSetContentHandler(nbRegistry, csrfService))
api.Path("/notebook/{name:.+}/exec").HandlerFunc(httphandler.ApiNotebookExecHandler(nbRegistry, csrfService, useDocker))
api.Path("/notebook/{name:.+}/stop").HandlerFunc(httphandler.ApiNotebookStopHandler(nbRegistry, csrfService))
root.PathPrefix("/").Handler(fs)
return root
}