-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (33 loc) · 883 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
package main
import (
"fmt"
"os"
impl "github.com/KevinGoode/inventory/service"
"go.uber.org/dig"
)
func buildContainer() *dig.Container {
container := dig.New()
container.Provide(impl.NewDatabaseFactory)
container.Provide(impl.NewCassandraDbCreater)
container.Provide(impl.NewParameterReader)
container.Provide(impl.NewParameterValidator)
container.Provide(impl.NewCommandRunner)
return container
}
func main() {
//This code uses dig dependency injector for more details see
//https://godoc.org/go.uber.org/dig
//https://blog.drewolson.org/dependency-injection-in-go
container := buildContainer()
err := container.Invoke(func(runner impl.CommandRunnerAPI) {
exitCode, OutputMessage := runner.Run()
if exitCode == 0 {
fmt.Println(OutputMessage)
} else {
os.Exit(exitCode)
}
})
if err != nil {
fmt.Println("General error executing command")
}
}