-
Notifications
You must be signed in to change notification settings - Fork 29
/
bloomapi.go
71 lines (63 loc) · 1.38 KB
/
bloomapi.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
69
70
71
package main
import (
"os"
"fmt"
"log"
"log/syslog"
"github.com/spf13/viper"
"github.com/untoldone/bloomapi/cmd"
"github.com/getsentry/raven-go"
)
func showUsage() {
fmt.Println("Usage: bloomapi <command>")
fmt.Println("=============================\n")
fmt.Println("Avaialable commands:")
fmt.Println("bloomapi server # run BloomAPI server")
fmt.Println("bloomapi bootstrap # setup BloomAPI shared schema")
fmt.Println("bloomapi drop # remove all BloomAPI shared tables")
}
func main() {
if (len(os.Args) != 2) {
fmt.Println("Invalid command usage\n")
showUsage()
os.Exit(1)
}
arg := os.Args[1]
viper.SetConfigName("config")
viper.AddConfigPath("./")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
dsn := viper.GetString("sentryDSN")
if dsn != "" {
raven.SetDSN(dsn)
}
logStyle := viper.GetString("generalLogger")
switch logStyle {
case "syslog":
logwriter, e := syslog.New(syslog.LOG_NOTICE, "bloomapi")
if e != nil {
fmt.Println("Error initializing syslog")
os.Exit(1)
}
log.SetOutput(logwriter)
case "stdout":
default:
fmt.Println("Invalid logger:", logStyle, "please select 'syslog' or 'stdout'")
os.Exit(1)
}
switch arg {
case "server":
cmd.Server()
case "bootstrap":
cmd.Bootstrap()
case "drop":
cmd.Drop()
default:
fmt.Println("Invalid command:", arg)
showUsage()
os.Exit(1)
}
}