This repository has been archived by the owner on Mar 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
90 lines (77 loc) · 1.92 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
85
86
87
88
89
90
package main
import (
"fmt"
"time"
"github.com/gobook/bookserver/conf"
"github.com/gobook/bookserver/middlewares"
"github.com/gobook/bookserver/models"
"github.com/gobook/bookserver/routers"
"github.com/lunny/tango"
"github.com/tango-contrib/flash"
"github.com/tango-contrib/renders"
"github.com/tango-contrib/session"
"github.com/tango-contrib/xsrf"
)
func main() {
err := conf.Init()
if err != nil {
fmt.Println(err)
return
}
err = models.Init()
if err != nil {
fmt.Println(err)
return
}
t := tango.Classic()
sess := session.New()
t.Use(
tango.Static(tango.StaticOptions{
RootPath: conf.BooksRootPath,
Prefix: "read",
}),
xsrf.New(20*time.Minute),
middlewares.Auth(sess),
renders.New(renders.Options{
Reload: true,
Directory: "templates",
//Extensions: []string{".html"},
Vars: renders.T{
"AppUrl": "/",
"AppLogo": "/public/images/logo.png",
},
}),
sess,
flash.Flashes(sess),
)
t.Get("/", new(routers.Home))
t.Any("/login", new(routers.Login))
t.Get("/logout", new(routers.Logout))
t.Any("/register", new(routers.Register))
t.Group("/user", func(g *tango.Group) {
//g.Get("/*name", new(routers.User))
})
t.Group("/myBooks", func(g *tango.Group) {
g.Get("/", new(routers.MyBooks))
g.Get("/:id/down", new(routers.DownBook))
g.Get("/:id/up", new(routers.UpBook))
g.Get("/:id/update", new(routers.UpdateBook))
g.Get("/:id/del", new(routers.DelBook))
})
t.Group("/book", func(g *tango.Group) {
//g.Get("/:id", new(routers.Book))
})
t.Group("/publish", func(g *tango.Group) {
g.Any("/", new(routers.Publish))
g.Any("/*path", new(routers.Publish))
})
t.Group("/auth", func(g *tango.Group) {
g.Get("/login/github", new(routers.LoginGithub))
})
t.Group("/github", func(g *tango.Group) {
g.Any("/", new(routers.GithubPush))
//g.Get("/auth", new(routers.Github))
//g.Get("/callback", new(routers.GithubCallback))
})
t.Run(conf.Listen)
}