-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
63 lines (46 loc) · 1.21 KB
/
server.go
File metadata and controls
63 lines (46 loc) · 1.21 KB
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
package main
import (
"context"
"github.com/MinorvaFalk/go-graphql-practice/core/utils"
handler "github.com/MinorvaFalk/go-graphql-practice/handlers"
"github.com/MinorvaFalk/go-graphql-practice/module"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
)
func main() {
app := fx.New(
module.Module,
fx.Invoke(startup),
)
app.Run()
// l := log.New(os.Stdout, "[Book API] ", log.LstdFlags)
// env := utils.NewEnv(l)
// db := utils.GetDatabaseGORM(l, env)
// br := repository.NewBookPostgresRepository(l, db.DB)
// bs := services.NewBookService(l, br)
// ar := repository.NewAuthorPostgresRepository(l, db.DB)
// as := services.NewAuthorService(l, ar)
// r := gin.Default()
// r.Use(cors.Default())
// handler.NewGraphqlHandler(r, bs, as)
// // Handle REST Request
// // handler.NewRestHandler(r)
// go func() {
// }()
}
func startup(lifecycle fx.Lifecycle, db *utils.Database, env *utils.Env, handler handler.Handlers, r *gin.Engine) {
conn, _ := db.DB.DB()
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
go func() {
handler.SetupHandler()
r.Run(env.Port)
}()
return nil
},
OnStop: func(ctx context.Context) error {
conn.Close()
return nil
},
})
}