-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (41 loc) · 1.23 KB
/
main.go
File metadata and controls
55 lines (41 loc) · 1.23 KB
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
package main
import (
"context"
"flag"
"github.com/koderhut/memorynotes/config"
"github.com/koderhut/memorynotes/webapp"
"log"
"os"
"os/signal"
"time"
)
var c config.Parameters
func init() {
addr := flag.String("addr", "0.0.0.0:44666", "IP and port to bind to")
prefix := flag.String("path-prefix", "/api", "Path prefix for endpoints")
domain := flag.String("domain", "localhost", "Domain used for link generation")
cors := flag.String("cors", "http://localhost:44666", "Allowed hosts for access")
flag.Parse()
var err error
c, err = config.NewConfigParams(*addr, *prefix, *domain, *cors)
if nil != err {
panic("Unable to process config parameters. Shutting down!")
}
}
func main() {
wait := time.Second * 15
addr, _ := c.Addr()
// bootstrap the server and register the routes
srv := webapp.BootstrapServer(c)
log.Printf(">>> memory-notes web service is ready to receive requests on: [%s]\n", addr)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
// Block until we receive our signal.
<-c
// Create a deadline to wait for.
ctx, cancel := context.WithTimeout(context.Background(), wait)
defer cancel()
srv.Shutdown(ctx)
log.Println(">>> memory-notes web service has shutdown")
os.Exit(0)
}