-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 1.09 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
package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/taisa831/go-ddd/infrastructure/factory"
"github.com/taisa831/go-ddd/infrastructure/repository"
"github.com/taisa831/go-ddd/infrastructure/service"
"github.com/taisa831/go-ddd/interfaces/handler"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal(".env ファイルの読み込みに失敗しました。")
}
db, err := repository.OpenDB()
if err != nil {
log.Fatal(err)
}
sqlDB, err := db.DB()
if err != nil {
log.Fatal(err)
}
defer sqlDB.Close()
router := gin.Default()
r := repository.NewRepository(db)
us := service.NewUserService(r)
uh := handler.NewUserHandler(r, us)
router.POST("/users", uh.Create)
router.GET("/users", uh.List)
router.GET("/users/:userId", uh.Get)
router.PATCH("/users/:userId", uh.Update)
router.DELETE("/users/:userId", uh.Delete)
f := factory.NewCircleFactory()
cs := service.NewCircleService(r)
ch := handler.NewCircleHandler(r, f, cs)
router.POST("/circles", ch.Create)
router.POST("/circles/:circleId/join", ch.Join)
router.Run()
}