This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
64 lines (53 loc) · 1.57 KB
/
router.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
//go:generate go-bindata-assetfs frontend/...
import (
"log"
"net/http"
"net/http/pprof"
"github.com/julienschmidt/httprouter"
)
func NewRouter(h *Handlers, assets string, debug bool) *httprouter.Router {
router := httprouter.New()
// Wapper
router.GET("/api/ai", h.Index)
router.PUT("/api/ai/:uuid", h.New)
router.GET("/api/ai/:uuid", h.Get)
router.POST("/api/ai/:uuid/update", h.Update)
router.POST("/api/ai/:uuid/update/image", h.UpdateImage) // TODO: DEPRECATED
router.POST("/api/ai/:uuid/update/image/:id", h.UpdateImage)
//router.POST("/api/ai/:uuid/error", h.Error)
router.DELETE("/api/ai/:uuid", h.Delete)
// Docker
router.PUT("/api/docker", h.DockerNew)
// Dashboard Stream
router.GET("/api/stream", h.Stream)
// Dashboard
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
http.Redirect(w, r, "/dashboard/", http.StatusFound)
})
if assets == "builtin" {
router.ServeFiles("/dashboard/*filepath", assetFS())
} else {
router.ServeFiles("/dashboard/*filepath", http.Dir(assets))
}
// Debug
if debug {
log.Println("router:", "Debug routes enabled!")
router.HandlerFunc("GET", "/debug/pprof/", pprof.Index)
router.GET("/debug/pprof/:profile", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
switch p.ByName("profile") {
case "cmdline":
pprof.Cmdline(w, r)
case "profile":
pprof.Profile(w, r)
case "symbol":
pprof.Symbol(w, r)
case "trace":
pprof.Trace(w, r)
default:
pprof.Handler(p.ByName("profile")).ServeHTTP(w, r)
}
})
}
return router
}