-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (78 loc) · 2.67 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
package main
import (
"blog-go/src/config"
"blog-go/src/controller"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/roylee0704/gron"
"github.com/rs/cors"
"time"
)
func main() {
app := newApp()
app.Listen(":8081")
}
func newApp() *iris.Application {
app := iris.Default()
app.Logger().SetLevel("DEBUG")
//+--------------------------------+ static resources
app.HandleDir("/uploads", iris.Dir("./uploads"))
app.HandleDir("/", iris.Dir("./dist"))
app.RegisterView(iris.HTML("./dist", ".html"))
//+--------------------------------+
//+--------------------------------+ CORS config
c := cors.AllowAll()
app.WrapRouter(c.ServeHTTP)
//+--------------------------------+
//+--------------------------------+ cron config
job := gron.New()
job.AddFunc(gron.Every(24*time.Hour), controller.StatisticsUpdate)
job.Start()
//+--------------------------------+ router config
app.Get("/", func(ctx *context.Context) {
ctx.View("index.html")
})
app.Post("/login", controller.Login)
app.Get("/updateStatistics", controller.PvStatisticsPerDay)
authApi := app.Party("")
authApi.Use(config.J.Verify)
authApi.Get("/currentUserName", controller.CurrentUserName)
authApi.Get("/currentUserId", controller.CurrentUserId)
authApi.Get("/currentUserEmail", controller.CurrentUserEmail)
authApi.Get("/isAdmin", controller.IsAdmin)
authApi.Put("/updateUserEmail", controller.UpdateUserEmail)
authApi.Get("/logout", controller.Logout)
admin := authApi.Party("/admin")
{
admin.Get("/user", controller.GetUserByNickname)
admin.Get("/user/{id:int}", controller.GetUserById)
admin.Get("/roles", controller.GetAllRoles)
admin.Post("/user", controller.AddUser)
admin.Put("/user/role", controller.UpdateUserRoles)
admin.Put("/user/enabled", controller.SwitchUserEnableStatus)
admin.Delete("/user/{id:int}", controller.DeleteUserById)
cate := admin.Party("/category")
{
cate.Get("/all", controller.GetAllCategories)
cate.Post("/", controller.AddNewCategory)
cate.Put("/", controller.UpdateCategory)
cate.Delete("/{ids:string}", controller.DeleteCateById)
}
arti := admin.Party("/article")
{
arti.Get("/all", controller.GetArticleByStateForAdmin)
arti.Put("/dustbin", controller.DeleteArticleByAdmin)
}
}
article := authApi.Party("/article")
{
article.Get("/dataStatistics", controller.GetDataStatistics)
article.Get("/all", controller.GetArticleByState)
article.Get("/{aid:int}", controller.GetArticleById)
article.Post("/", controller.AddNewArticle)
article.Post("/uploadimg", controller.UploadImage)
article.Put("/dustbin", controller.UpdateArticleState)
article.Put("/restore", controller.RestoreArticle)
}
return app
}