-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
59 lines (43 loc) · 1.03 KB
/
server.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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func sanitizeWebRoot(path string) string {
if len(path) < 2 {
return "/"
} else if len(path) > 1 && path[len(path)-1] != '/' {
return path + "/"
}
return path
}
func runServer(assets, bind string, debug bool) {
var root *gin.RouterGroup
gin.DisableConsoleColor()
if debug {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
router := gin.Default()
static, templates := setupTemplate(assets, router)
root = router.Group(sanitizeWebRoot(webroot))
serverAddAssets(root, assets, static, templates)
root.GET("/", func(c *gin.Context) {
c.HTML(200, "index.tmpl", gin.H{
"root": webroot,
"list": notebook.list(),
})
})
serverAddAbout(root)
serverAddSettings(root)
serverAddPage(root)
pipe := root.Group("/pipe")
serverAddPipe(pipe)
markdown := root.Group("/markdown")
serverAddMarkdown(markdown)
output := root.Group("/output")
serverAddOutput(output)
fmt.Printf("Server listening at http://%s\n", bind)
router.Run(bind)
}