-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (39 loc) · 887 Bytes
/
main.go
File metadata and controls
49 lines (39 loc) · 887 Bytes
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
package main
import (
"context"
"go-drive/common"
"go-drive/common/registry"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
ch := registry.NewComponentHolder()
engine, e := Initialize(context.Background(), ch)
if e != nil {
log.Fatalln(e)
}
dispose := func() { _ = ch.Dispose() }
conf := ch.Get(registry.KeyConfig).(common.Config)
server := &http.Server{Addr: conf.Listen, Handler: engine}
go func() {
if e := server.ListenAndServe(); e != nil && e != http.ErrServerClosed {
dispose()
log.Fatalln(e)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Signal received. Shutting down...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if e := server.Shutdown(ctx); e != nil {
dispose()
log.Fatalln(e)
}
dispose()
}