forked from unders/docit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (36 loc) · 1.04 KB
/
main.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/GeertJohan/go.rice"
"github.com/unders/docit/cli"
"github.com/unders/docit/handler/members"
"github.com/unders/docit/handler/projects"
"github.com/unders/docit/handler/root"
"github.com/unders/docit/template"
)
func main() {
switch cmd, arg := cli.Parse(); true {
case cmd == "serve":
template.Init(rice.MustFindBox("embedded_assets/tmpl"), arg.Name)
routes(arg)
fmt.Printf("Serve files at http://0.0.0.0:%s from %s\n", arg.Port, arg.Root)
log.Fatal(http.ListenAndServe(":"+arg.Port, nil))
case cmd == "version":
cli.PrintVersion()
default:
cli.Usage()
}
}
func routes(arg cli.Arg) {
http.HandleFunc("/", root.Handle(arg))
http.HandleFunc("/projects", projects.Handle(arg.Root))
if arg.MemberFile != "" {
path := arg.Root + "/" + arg.MemberFile
http.HandleFunc("/members", members.Handle(path))
}
fileServer := http.FileServer(rice.MustFindBox("embedded_assets").HTTPBox())
h := http.StripPrefix("/embedded_assets/", fileServer)
http.Handle("/embedded_assets/", h)
}