/
main.go
67 lines (54 loc) · 1.32 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 (
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/itsyouonline/identityserver/db"
"github.com/itsyouonline/identityserver/routes"
)
func main() {
app := cli.NewApp()
app.Name = "Identity server"
app.Version = "0.1-Dev"
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
var debugLogging bool
var bindAddress, dbConnectionString string
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
Destination: &debugLogging,
},
cli.StringFlag{
Name: "bind, b",
Usage: "Bind address",
Value: ":8080",
Destination: &bindAddress,
},
cli.StringFlag{
Name: "connectionstring, c",
Usage: "Mongodb connection string",
Value: "127.0.0.1:27017",
Destination: &dbConnectionString,
},
}
app.Before = func(c *cli.Context) error {
if debugLogging {
log.SetLevel(log.DebugLevel)
log.Debug("Debug logging enabled")
log.Debug(app.Name, "-", app.Version)
}
return nil
}
app.Action = func(c *cli.Context) {
// Connect to DB!
go db.Connect(dbConnectionString)
defer db.Close()
// Get router!
r := routes.GetRouter()
log.Info("Listening on ", bindAddress)
log.Fatal(http.ListenAndServe(bindAddress, r))
}
app.Run(os.Args)
}