-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 2.06 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
package main
import (
"github.com/ChowRobin/fantim/middleware"
"github.com/ChowRobin/fantim/views/connection"
"github.com/ChowRobin/fantim/views/group"
"github.com/ChowRobin/fantim/views/message"
"github.com/ChowRobin/fantim/views/relation"
"github.com/ChowRobin/fantim/views/user"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
store := cookie.NewStore([]byte("secret"))
/**
store.Options(sessions.Options{
Path: "/",
Domain: "localhost:3000",
MaxAge: int(time.Hour * 24 * 3),
Secure: false,
HttpOnly: false,
SameSite: 0,
})
*/
r.Use(sessions.Sessions("session_id", store))
r.Use(middleware.Cors())
needLogin := middleware.ApiOption{
Key: "login",
Ok: true,
}
r.POST("/user/login/", middleware.ApiDecorator(user.Login))
r.POST("/user/sign/up/", middleware.ApiDecorator(user.SignUp))
r.GET("/user/info/", middleware.ApiDecorator(user.Info, needLogin))
r.POST("/message/send/", middleware.ApiDecorator(message.Send, needLogin))
r.POST("/message/pull/", middleware.ApiDecorator(message.Pull, needLogin))
r.GET("/message/search/", middleware.ApiDecorator(message.Search, needLogin))
r.GET("/websocket/create/", connection.Handle)
r.POST("/relation/apply/create/", middleware.ApiDecorator(relation.CreateApply, needLogin))
r.POST("/relation/apply/update/", middleware.ApiDecorator(relation.UpdateApply, needLogin))
r.GET("/relation/apply/list/", middleware.ApiDecorator(relation.ListApply, needLogin))
r.GET("/relation/friend/list/", middleware.ApiDecorator(relation.ListFriend, needLogin))
r.POST("/group/create/", middleware.ApiDecorator(group.Create, needLogin))
r.GET("/group/list/", middleware.ApiDecorator(group.List, needLogin))
r.GET("/group/member/list/", middleware.ApiDecorator(group.ListMembers, needLogin))
r.GET("/group/search/", middleware.ApiDecorator(group.Search, needLogin))
r.POST("/group/apply/update/", middleware.ApiDecorator(relation.UpdateGroupApply, needLogin))
_ = r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}