forked from bitbomdev/minefield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (39 loc) · 1.03 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
package main
import (
"fmt"
"net/http"
_ "net/http/pprof" // Import for side-effect
"github.com/bit-bom/minefield/cmd/root"
"github.com/bit-bom/minefield/pkg/graph"
"github.com/bit-bom/minefield/pkg/storages"
"github.com/spf13/cobra"
"go.uber.org/fx"
)
func main() {
var pprofEnabled bool
var pprofAddr string
app := fx.New(
storages.NewRedisStorageModule("localhost:6379"),
fx.Invoke(func(storage graph.Storage, shutdowner fx.Shutdowner) {
rootCmd := root.New(storage)
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
pprofEnabled, _ = cmd.Flags().GetBool("pprof")
pprofAddr, _ = cmd.Flags().GetString("pprof-addr")
if pprofEnabled {
go func() {
fmt.Printf("Starting pprof server on %s\n", pprofAddr)
http.ListenAndServe(pprofAddr, nil)
}()
}
}
if err := rootCmd.Execute(); err != nil {
panic(err)
}
if err := shutdowner.Shutdown(); err != nil {
panic(fmt.Sprintf("Failed to shutdown fx err = %s", err))
}
}),
fx.NopLogger,
)
app.Run()
}