-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
51 lines (43 loc) · 1010 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
48
49
50
51
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"registry-factory/lib"
"syscall"
)
func main() {
yamlFile := flag.String("c", "", "config yaml file")
flag.Parse()
//Load config
if err := lib.Config.Load(*yamlFile); err != nil {
log.Fatal(err)
}
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
s := lib.NewProxyServer(ctx)
done := make(chan error, 1)
go func() {
if err := s.Start(); err != nil {
done <- err
}
}()
log.Printf("Server is listening at %s:%d...\n", lib.Config.Host, lib.Config.Port)
defer log.Println("Server is shutdown")
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, os.Kill)
select {
case err := <-done:
log.Fatalf("Server error: %s\n", err)
case <-ctx.Done():
log.Println("ctx done!")
case <-sig:
log.Println("Gracefully shutting down the server...")
if err := s.Stop(); err != nil {
log.Printf("Failed to shutdown server with error: %s\n", err)
}
}
}