forked from nenene-pupupu/disgord-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (70 loc) · 1.78 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
//go:generate go run -mod=mod github.com/swaggo/swag/cmd/swag init
package main
import (
"disgord/controller"
_ "disgord/docs"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title disGOrd API
func main() {
c := controller.New()
defer c.Close()
r := gin.Default()
config := cors.DefaultConfig()
config.AllowOrigins = []string{"http://localhost:5173"}
config.AllowCredentials = true
config.AllowWebSockets = true
config.AddAllowHeaders("Authorization")
r.Use(cors.New(config))
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
public := r.Group("")
{
auth := public.Group("/auth")
{
auth.POST("/sign-up", c.SignUp)
auth.POST("/sign-in", c.SignIn)
auth.POST("/refresh", c.Refresh)
auth.POST("/sign-out", c.SignOut)
}
chatroom := public.Group("/chatrooms")
{
chatroom.GET("", c.GetAllChatrooms)
}
}
private := r.Group("")
private.Use(c.JWTAuthMiddleware())
{
user := private.Group("/users")
{
user.GET("", c.GetAllUsers)
user.GET("/:id", c.GetUserByID)
user.GET("/me", c.GetMyProfile)
user.PATCH("/me", c.UpdateMyProfile)
user.DELETE("/me", c.CancelAccount)
}
chatroom := private.Group("/chatrooms")
{
chatroom.GET("/:id", c.GetChatroomByID)
chatroom.POST("", c.CreateChatroom)
chatroom.PATCH("/:id", c.UpdateChatroom)
chatroom.DELETE("/:id", c.DeleteChatroom)
chatroom.POST("/:id/join", c.JoinChatroom)
}
chat := private.Group("/chats")
{
chat.GET("", c.GetAllChats)
chat.GET("/:id", c.GetChatByID)
chat.POST("", c.CreateChat)
chat.PATCH("/:id", c.UpdateChat)
chat.DELETE("/:id", c.DeleteChat)
}
ws := private.Group("/ws")
{
ws.GET("", c.ConnectWebsocket)
}
}
r.Run()
}