-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (46 loc) · 1.28 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
package main
import (
"flag"
"fmt"
"github.com/spf13/viper"
"log"
"github.com/scottdelly/goql/api"
"github.com/scottdelly/goql/db_client"
"github.com/spf13/pflag"
)
func main() {
log.Println("==> Starting up")
viper.SetDefault("api_host_name", ":8080")
// using standard library "flag" package
flag.String("db_host_name", "localhost", "override host name for database")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
panic(fmt.Errorf("fatal error binding to cmd line %s", err))
}
viper.AutomaticEnv()
viper.SetConfigName("config")
viper.AddConfigPath(".")
err = viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %s", err))
}
apiHostName := viper.GetString("api_host_name")
apiErr := make(chan error)
go func() {
gqlAPI := new(api.GQLApi)
apiErr <- gqlAPI.Start(apiHostName)
}()
dbHostName := viper.GetString("db_host_name")
dbUser := viper.GetString("db_user")
dbPass := viper.GetString("db_pass")
dbBootstrap := viper.GetBool("db_bootstrap")
go func() {
dbc := new(db_client.DBClient)
api.SetDbClient(dbc)
dbc.Start(dbUser, dbPass, dbHostName, dbBootstrap)
}()
err = <-apiErr
log.Fatal(err.Error())
}