-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
151 lines (118 loc) · 5.05 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"fmt"
"github.com/astaxie/beego"
"github.com/beego/social-auth"
"github.com/movelikeriver/ishow/modules/utils"
"github.com/movelikeriver/ishow/routers/admin"
"github.com/movelikeriver/ishow/routers/api"
"github.com/movelikeriver/ishow/routers/article"
"github.com/movelikeriver/ishow/routers/attachment"
"github.com/movelikeriver/ishow/routers/auth"
"github.com/movelikeriver/ishow/routers/base"
"github.com/movelikeriver/ishow/routers/post"
"github.com/movelikeriver/ishow/setting"
_ "github.com/go-sql-driver/mysql"
)
// We have to call a initialize function manully
// because we use `bee bale` to pack static resources
// and we cannot make sure that which init() execute first.
func initialize() {
setting.LoadConfig()
if err := utils.InitSphinxPools(); err != nil {
beego.Error(fmt.Sprint("sphinx init pool", err))
}
setting.SocialAuth = social.NewSocial("/login/", auth.SocialAuther)
setting.SocialAuth.ConnectSuccessURL = "/settings/profile"
setting.SocialAuth.ConnectFailedURL = "/settings/profile"
setting.SocialAuth.ConnectRegisterURL = "/register/connect"
setting.SocialAuth.LoginURL = "/login"
}
func main() {
beego.SetLogFuncCall(true)
initialize()
beego.Info("AppPath:", beego.AppPath)
if setting.IsProMode {
beego.Info("Product mode enabled")
} else {
beego.Info("Develment mode enabled")
}
beego.Info(beego.AppName, setting.APP_VER, setting.AppUrl)
if !setting.IsProMode {
beego.SetStaticPath("/static_source", "static_source")
beego.DirectoryIndex = true
}
// Add Filters
beego.InsertFilter("/img/*", beego.BeforeRouter, attachment.ImageFilter)
beego.InsertFilter("/captcha/*", beego.BeforeRouter, setting.Captcha.Handler)
// Register routers.
posts := new(post.PostListRouter)
beego.Router("/", posts, "get:Home")
beego.Router("/:slug(recent|best|cold|favs|follow)", posts, "get:Navs")
beego.Router("/category/:slug", posts, "get:Category")
beego.Router("/topic/:slug", posts, "get:Topic;post:TopicSubmit")
postR := new(post.PostRouter)
beego.Router("/new", postR, "get:New;post:NewSubmit")
beego.Router("/post/:post([0-9]+)", postR, "get:Single;post:SingleSubmit")
beego.Router("/post/:post([0-9]+)/edit", postR, "get:Edit;post:EditSubmit")
if setting.NativeSearch || setting.SphinxEnabled {
searchR := new(post.SearchRouter)
beego.Router("/search", searchR, "get:Get")
}
user := new(auth.UserRouter)
beego.Router("/user/:username/comments", user, "get:Comments")
beego.Router("/user/:username/posts", user, "get:Posts")
beego.Router("/user/:username/following", user, "get:Following")
beego.Router("/user/:username/followers", user, "get:Followers")
beego.Router("/user/:username/favs", user, "get:Favs")
beego.Router("/user/:username", user, "get:Home")
login := new(auth.LoginRouter)
beego.Router("/login", login, "get:Get;post:Login")
beego.Router("/logout", login, "get:Logout")
beego.InsertFilter("/login/*/access", beego.BeforeRouter, auth.OAuthAccess)
beego.InsertFilter("/login/*", beego.BeforeRouter, auth.OAuthRedirect)
socialR := new(auth.SocialAuthRouter)
beego.Router("/register/connect", socialR, "get:Connect;post:ConnectPost")
register := new(auth.RegisterRouter)
beego.Router("/register", register, "get:Get;post:Register")
beego.Router("/active/success", register, "get:ActiveSuccess")
beego.Router("/active/:code([0-9a-zA-Z]+)", register, "get:Active")
settings := new(auth.SettingsRouter)
beego.Router("/settings/profile", settings, "get:Profile;post:ProfileSave")
forgot := new(auth.ForgotRouter)
beego.Router("/forgot", forgot)
beego.Router("/reset/:code([0-9a-zA-Z]+)", forgot, "get:Reset;post:ResetPost")
upload := new(attachment.UploadRouter)
beego.Router("/upload", upload, "post:Post")
apiR := new(api.ApiRouter)
beego.Router("/api/user", apiR, "post:Users")
beego.Router("/api/md", apiR, "post:Markdown")
adminDashboard := new(admin.AdminDashboardRouter)
beego.Router("/admin", adminDashboard)
adminR := new(admin.AdminRouter)
beego.Router("/admin/model/get", adminR, "post:ModelGet")
beego.Router("/admin/model/select", adminR, "post:ModelSelect")
routes := map[string]beego.ControllerInterface{
"user": new(admin.UserAdminRouter),
"post": new(admin.PostAdminRouter),
"comment": new(admin.CommentAdminRouter),
"topic": new(admin.TopicAdminRouter),
"category": new(admin.CategoryAdminRouter),
"article": new(admin.ArticleAdminRouter),
}
for name, router := range routes {
beego.Router(fmt.Sprintf("/admin/:model(%s)", name), router, "get:List")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id(new)", name), router, "get:Create;post:Save")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)", name), router, "get:Edit;post:Update")
beego.Router(fmt.Sprintf("/admin/:model(%s)/:id([0-9]+)/:action(delete)", name), router, "get:Confirm;post:Delete")
}
// "robot.txt"
beego.Router("/robot.txt", &base.RobotRouter{})
articleR := new(article.ArticleRouter)
beego.Router("/:slug", articleR, "get:Show")
if beego.RunMode == "dev" {
beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
}
// For all unknown pages.
beego.Run()
}