-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.go
42 lines (33 loc) · 993 Bytes
/
bootstrap.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
package internal
import (
"context"
"fmt"
"testing"
"github.com/ankorstore/yokai/fxcore"
"github.com/ankorstore/yokai/fxhttpserver"
"go.uber.org/fx"
)
func init() {
RootDir = fxcore.RootDir(1)
}
// RootDir is the application root directory.
var RootDir string
// Bootstrapper can be used to load modules, options, dependencies, routing and bootstraps the application.
var Bootstrapper = fxcore.NewBootstrapper().WithOptions(
// modules registration
fxhttpserver.FxHttpServerModule,
// dependencies registration
Register(),
// routing registration
Router(),
)
// Run starts the application, with a provided [context.Context].
func Run(ctx context.Context) {
Bootstrapper.WithContext(ctx).RunApp()
}
// RunTest starts the application in test mode, with an optional list of [fx.Option].
func RunTest(tb testing.TB, options ...fx.Option) {
tb.Helper()
tb.Setenv("APP_CONFIG_PATH", fmt.Sprintf("%s/configs", RootDir))
Bootstrapper.RunTestApp(tb, fx.Options(options...))
}