-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (40 loc) · 862 Bytes
/
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
package main
//import "fmt"
import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
database()
store := cookie.NewStore([]byte("username"))
r.Use(sessions.Sessions("session", store))
r.GET("/", func(c *gin.Context) {
c.String(200, "message board")
})
r.POST("/register", func(c *gin.Context) {
register(c)
})
r.POST("/login", func(c *gin.Context) {
login(c)
})
r.GET("/logout", func(c *gin.Context) {
logout(c)
})
r.POST("/addMsg", func(c *gin.Context) {
if getSession(c) {
addMsg(c)
} else {
c.JSON(400, gin.H{"code": "400", "Msg": "请先登录!"})
}
})
r.GET("/delMsg", func(c *gin.Context) {
if getSession(c) {
delMsg(c)
} else {
c.JSON(400, gin.H{"code": "400", "Msg": "请先登录!"})
}
})
r.Run("4444")
}