-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.go
68 lines (58 loc) · 1.65 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"runtime"
"github.com/pg-sharding/spqr/coordinator/app"
"github.com/pg-sharding/spqr/coordinator/provider"
"github.com/pg-sharding/spqr/pkg"
"github.com/pg-sharding/spqr/pkg/config"
"github.com/pg-sharding/spqr/pkg/spqrlog"
"github.com/pg-sharding/spqr/qdb"
"github.com/spf13/cobra"
)
var (
cfgPath string
qdbImpl string
gomaxprocs int
)
var rootCmd = &cobra.Command{
Use: "spqr-coordinator run --config `path-to-config`",
Short: "spqr-coordinator",
Long: "spqr-coordinator",
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Version: pkg.SpqrVersionRevision,
SilenceUsage: false,
SilenceErrors: false,
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.LoadCoordinatorCfg(cfgPath); err != nil {
return err
}
if gomaxprocs > 0 {
runtime.GOMAXPROCS(gomaxprocs)
}
db, err := qdb.NewXQDB(qdbImpl)
if err != nil {
return err
}
// frontend
frTLS, err := config.CoordinatorConfig().FrontendTLS.Init(config.CoordinatorConfig().Host)
if err != nil {
return fmt.Errorf("init frontend TLS: %w", err)
}
coordinator := provider.NewCoordinator(frTLS, db)
app := app.NewApp(coordinator)
return app.Run(true)
},
}
func init() {
rootCmd.PersistentFlags().StringVarP(&cfgPath, "config", "c", "/etc/spqr/coordinator.yaml", "path to config file")
rootCmd.PersistentFlags().StringVarP(&qdbImpl, "qdb-impl", "", "etcd", "which implementation of QDB to use.")
rootCmd.PersistentFlags().IntVarP(&gomaxprocs, "gomaxprocs", "", 0, "GOMAXPROCS value")
}
func main() {
if err := rootCmd.Execute(); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
}
}