-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (40 loc) · 956 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
44
45
46
47
package main
import (
"context"
"github.com/gin-gonic/gin"
"noan.dev/uniklub/api/v1/clubs"
"noan.dev/uniklub/constants"
"noan.dev/uniklub/database"
"noan.dev/uniklub/middlewares"
)
func main() {
ctx := context.Background()
driver, err := database.Init(ctx, database.ConnectionInformation{
Username: "postgres",
Password: "postgres",
Address: "127.0.0.1",
Port: 5432,
Database: "app",
})
if err != nil {
panic(err)
}
ctx = context.WithValue(ctx, constants.DatabaseCtx, driver)
gin.SetMode(gin.DebugMode)
r := gin.Default()
r.Use(middlewares.HandleSecurity(ctx))
v1Router := r.Group("/v1")
{
clubsRouter := v1Router.Group("/clubs")
{
clubsRouter.GET("/", clubs.Get(ctx))
clubsRouter.GET("/:id", clubs.GetById(ctx))
clubsRouter.POST("/", clubs.Add(ctx))
clubsRouter.POST("/:id", clubs.Update(ctx))
clubsRouter.PUT("/:id", clubs.Update(ctx))
}
}
if err := r.Run(); err != nil {
panic(err)
}
}