-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (66 loc) · 2.02 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"net/http"
"regexp"
"github.com/guotie/config"
"github.com/smtc/goutils"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
"github.com/smtc/gotodo/models"
)
var (
configFn = flag.String("config", "./config.json", "config file path")
)
func main() {
config.ReadCfg(*configFn)
models.InitDB()
run()
}
func run() {
// static files
goji.Get("/assets/*", http.FileServer(http.Dir("./")))
// route
goji.Get("/", IndexHandler)
goji.Get("/login", LoginPage)
goji.Get("/logout", Logout)
goji.Get("/mustlogin", MustLogin)
goji.Post("/login", Login)
goji.Get("/user/", UserList)
goji.Get("/user/roles", UserRoles)
goji.Get("/user/select", UserSelect)
goji.Get("/user/info", UserInfo)
goji.Post("/user/", UserSave)
goji.Delete("/user/", UserDelete)
goji.Get("/project/", ProjectList)
goji.Get("/project/select", ProjectSelect)
goji.Post("/project/", ProjectSave)
goji.Delete("/project/", ProjectDelete)
goji.Get("/project/level", ProjectLevel)
goji.Get("/task/", TaskList)
goji.Get("/task/mine", TaskMine)
goji.Post("/task/", TaskSave)
goji.Get("/task/weights", TaskWeightSelect)
goji.Post("/task/finish", TaskFinish)
goji.Post("/task/refresh", TaskRefresh)
goji.Delete("/task/", TaskDelete)
goji.Get(regexp.MustCompile(`^/report/(?P<project_id>.+)/(?P<task_id>.+)$`), ReportList)
goji.Post("/report/", ReportSave)
goji.Get(regexp.MustCompile(`^/(?P<model>.+)\.(?P<fn>.+):(?P<param>.+)$`), TemplateHandler)
goji.Get(regexp.MustCompile(`^/(?P<model>.+)\.(?P<fn>.+)$`), TemplateHandler)
goji.Get(regexp.MustCompile(`^/(?P<model>.+)_(?P<fn>.+)$`), TemplateHandler)
goji.NotFound(goutils.NotFound)
goji.Serve()
}
func IndexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
h := goutils.HttpHandler(c, w, r)
h.RenderHtml("/index.html")
}
/*
模板页暂时以 model.fn:param 分级
*/
func TemplateHandler(c web.C, w http.ResponseWriter, r *http.Request) {
temp := fmt.Sprintf("/%s_%s.html", c.URLParams["model"], c.URLParams["fn"])
goutils.Render(w).RenderHtml(temp)
}