-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
54 lines (45 loc) · 1.16 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
package main
import (
"flag"
"time"
"github.com/martenwallewein/go-sample-microservice/api"
"github.com/martenwallewein/go-sample-microservice/dbs"
"github.com/martenwallewein/go-sample-microservice/seeds"
log "github.com/sirupsen/logrus"
)
var (
laddr = flag.String("addr", ":8880", "Local address for the HTTP API")
loglevel = flag.String("loglevel", "INFO", "Log-level (ERROR|WARN|INFO|DEBUG|TRACE)")
initialSeedFile = flag.String("initialSeedFile", "", "Run one-time seeds passing path to a valid JSON seed file")
)
func configureLogging() error {
l, err := log.ParseLevel(*loglevel)
if err != nil {
return err
}
log.SetLevel(l)
log.SetFormatter(&log.JSONFormatter{
TimestampFormat: time.RFC3339Nano,
DisableHTMLEscape: true,
})
return nil
}
func main() {
flag.Parse()
if err := configureLogging(); err != nil {
log.Fatal(err)
}
err := dbs.InitializeDatabaseLayer()
if err != nil {
log.Fatal(err)
}
if initialSeedFile != nil && *initialSeedFile != "" {
if err = seeds.RunSeeds(*initialSeedFile); err != nil {
log.Fatal(err)
}
}
api := api.NewRESTApiV1()
if err = api.Serve(*laddr); err != nil {
log.Fatal(err)
}
}