summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go75
1 files changed, 0 insertions, 75 deletions
diff --git a/main.go b/main.go
deleted file mode 100644
index 1be1067..0000000
--- a/main.go
+++ /dev/null
@@ -1,75 +0,0 @@
1package main
2
3import (
4 "encoding/json"
5 "net/http"
6 "os"
7
8 "github.com/go-chi/chi/v5"
9)
10
11type App struct {
12 Operations []*Operation
13 Filesystem *Filesystem
14}
15
16func main() {
17 router := chi.NewRouter()
18
19 app := &App{
20 Operations: []*Operation{},
21 Filesystem: NewFilesystem(),
22 }
23
24 router.Get("/", func(w http.ResponseWriter, r *http.Request) {
25 w.Header().Add("Content-Type", "text/html")
26 file, _ := os.ReadFile("index.html")
27 w.Write(file)
28 })
29 router.Route("/api", func(r chi.Router) {
30 r.Get("/view", view)
31 r.Get("/filesystem/*", h(app, filesystemGet))
32 r.Post("/filesystem/*", h(app, filesystemPost))
33 r.Delete("/filesystem/*", h(app, filesystemDelete))
34 })
35
36 if err := http.ListenAndServe("0.0.0.0:5000", router); err != nil {
37 panic(err)
38 }
39}
40
41func h(app *App, f func(*App, http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
42 return func(w http.ResponseWriter, r *http.Request) {
43 f(app, w, r)
44 }
45}
46
47func view(w http.ResponseWriter, r *http.Request) {
48 w.Write([]byte("Hi"))
49}
50
51func filesystemGet(app *App, w http.ResponseWriter, r *http.Request) {
52 path, err := ParsePath("/" + chi.URLParam(r, "*"))
53 if err != nil {
54 panic(err)
55 }
56
57 // response := map[string]interface{}{
58 // "path": path,
59 // "message": "Filesystem path requested",
60 // }
61
62 entry := app.Filesystem.GetEntry(path)
63
64 w.Header().Set("Content-Type", "application/json")
65 json.NewEncoder(w).Encode(entry)
66}
67
68func filesystemPost(app *App, w http.ResponseWriter, r *http.Request) {
69 if err := r.ParseMultipartForm(1024 * 1024); err != nil {
70 panic(err)
71 }
72
73}
74
75func filesystemDelete(app *App, w http.ResponseWriter, r *http.Request) {}