add initial application structure with configuration, logging, and health check endpoints
This commit is contained in:
25
internal/infra/db/ent.go
Normal file
25
internal/infra/db/ent.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
"epic-ent/internal/config"
|
||||
"epic-ent/internal/ent"
|
||||
)
|
||||
|
||||
func NewEntClient(lc fx.Lifecycle, cfg *config.Config) (*ent.Client, error) {
|
||||
client, err := ent.Open("mysql", cfg.MySQL.DSN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStop: func(ctx context.Context) error {
|
||||
return client.Close()
|
||||
},
|
||||
})
|
||||
|
||||
return client, nil
|
||||
}
|
||||
Reference in New Issue
Block a user