forked from Apollo-Community/ApolloStats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
67 lines (60 loc) · 1.31 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
package main
import (
"log"
"os"
"github.com/Apollo-Community/ApolloStats/src"
"github.com/codegangsta/cli"
)
var (
g_addr string
g_database string
g_verbose bool
)
func main() {
app := cli.NewApp()
app.Version = apollostats.VERSION
app.Usage = "Run a web server, serving stats for Apollo."
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr, a",
Value: "127.0.0.1:8000",
Usage: "serve web pages on this address",
EnvVar: "APOLLOSTATS_ADDR",
Destination: &g_addr,
},
cli.StringFlag{
Name: "database, d",
Value: "user:password@/database",
Usage: "database authentication string",
EnvVar: "APOLLOSTATS_DBAUTH",
Destination: &g_database,
},
cli.BoolFlag{
Name: "verbose",
Usage: "run with verbose output",
Destination: &g_verbose,
},
}
app.Commands = []cli.Command{
{Name: "run", Usage: "Run the web server", Action: run_server},
}
app.Run(os.Args)
}
func run_server(c *cli.Context) {
db, e := apollostats.OpenDB(g_database, g_verbose)
if e != nil && g_verbose {
log.Printf("Failed to connect to the database:\n%s\n", e.Error())
}
i := apollostats.Instance{
Verbose: g_verbose,
DB: db,
}
e = i.Init()
if e != nil {
log.Panic(e)
}
e = i.Serve(g_addr)
if e != nil {
log.Panic(e)
}
}