-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (31 loc) · 710 Bytes
/
main.go
File metadata and controls
39 lines (31 loc) · 710 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
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/xray-web/web-check-api/config"
"github.com/xray-web/web-check-api/server"
)
func main() {
srv := server.New(config.New())
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
if err := srv.Run(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %v\n", err)
}
}()
<-done
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer func() {
// extra handling here, databases etc
cancel()
}()
if err := srv.Shutdown(ctx); err != nil {
log.Fatalf("Server Shutdown Failed:%+v", err)
}
}