-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (43 loc) · 885 Bytes
/
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
package main
import (
"context"
"dnscoffee/app"
"dnscoffee/datastore"
"dnscoffee/server"
"dnscoffee/version"
"flag"
"log"
"time"
)
var (
listenAddr = flag.String("listen", "127.0.0.1:8080", "ip:port to listen on")
)
// main
func main() {
flag.Parse()
log.Printf("version: %s", version.String())
// get datstore
// if no DB wait for valid connection
var ds *datastore.DataStore
var err error
ctx := context.Background()
for {
ds, err = datastore.New(ctx)
if err != nil {
log.Println(err)
log.Println("waiting for 30s")
time.Sleep(30 * time.Second)
} else {
break
}
}
defer ds.Close()
// get server and start application
coffeeServer, err := server.New(*listenAddr, server.DefaultAPIConfig)
if err != nil {
log.Fatal(err)
}
app.Start(ds, coffeeServer)
log.Printf("Server starting on %s", *listenAddr)
log.Fatal(coffeeServer.Start())
}