-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (72 loc) · 2.85 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
package main
import (
"github.com/gin-contrib/sessions"
//"github.com/gin-contrib/sessions/redis"
"project/config"
"project/controllers/admin"
"project/controllers/index"
"project/handler"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
//基于cookie
store := cookie.NewStore([]byte(config.SESSION_SECRET))
// 初始化基于redis的存储引擎
// 参数说明:
// 第1个参数 - redis最大的空闲连接数
// 第2个参数 - 数通信协议tcp或者udp
// 第3个参数 - redis地址, 格式,host:port
// 第4个参数 - redis密码
// 第5个参数 - session加密密钥
//store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", []byte(config.SESSION_SECRET))
r.Use(sessions.Sessions(config.SESSION_NAME, store))
r.Use(handler.CheckLogin())
r.LoadHTMLGlob("views/***/**/*")
r.Static("/static", "./static")
var indexController index.IndexController
r.GET("/", indexController.Index)
r.GET("/index", indexController.Index)
var articleController index.ArticleController
var courseController index.CourseController
r.GET("/courses", courseController.Courses)
r.GET("/chapter/list/:courseId", courseController.ChaperList)
r.GET("/course-article/list/:courseId/:chapterId", courseController.CourseArticleList)
r.GET("/course-article/detail/:articleId", courseController.ArticleDetail)
r.GET("/posts", articleController.Posts)
r.GET("/posts/detail/:seoLink", articleController.PostsDetail)
r.GET("/about", articleController.About)
r.GET("/categories", articleController.Categories)
r.GET("/tags", articleController.Tags)
r.GET("/search", articleController.Search)
var adminLogin admin.LoginController
var adminArticle admin.ArticleController
var adminTags admin.TagsController
var adminCategories admin.CategoriesController
v2 := r.Group("/ikebackend")
{
v2.GET("/login", adminLogin.Index)
v2.POST("/dologin", adminLogin.DoLogin)
v2.GET("/logout", adminLogin.Logout)
v2.GET("/article/index", adminArticle.Index)
v2.GET("/article/add", adminArticle.Add)
v2.POST("/article/doadd", adminArticle.Doadd)
v2.GET("/article/edit", adminArticle.Edit)
v2.POST("/article/doedit", adminArticle.Doedit)
v2.GET("/article/delete", adminArticle.Delete)
v2.GET("/tags/index", adminTags.Index)
v2.GET("/tags/add", adminTags.Add)
v2.POST("/tags/doadd", adminTags.Doadd)
v2.GET("/tags/edit", adminTags.Edit)
v2.POST("/tags/doedit", adminTags.Doedit)
v2.GET("/tags/delete", adminTags.Delete)
v2.GET("/categories/index", adminCategories.Index)
v2.GET("/categories/add", adminCategories.Add)
v2.POST("/categories/doadd", adminCategories.Doadd)
v2.GET("/categories/edit", adminCategories.Edit)
v2.POST("/categories/doedit", adminCategories.Doedit)
v2.GET("/categories/delete", adminCategories.Delete)
}
r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}