-
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (47 loc) · 1.15 KB
/
main.go
File metadata and controls
55 lines (47 loc) · 1.15 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"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
_ "net/http/pprof"
"github.com/zxh326/kite/pkg/common"
"github.com/zxh326/kite/pkg/version"
"k8s.io/klog/v2"
)
func main() {
klog.InitFlags(nil)
flag.Parse()
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
cm, err := initializeApp()
if err != nil {
log.Fatalf("Failed to initialize app: %v", err)
}
srv := &http.Server{
Addr: ":" + common.Port,
Handler: buildEngine(cm).Handler(),
}
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
klog.Fatalf("Failed to start server: %v", err)
}
}()
klog.Infof("Kite server started on port %s", common.Port)
klog.Infof("Version: %s, Build Date: %s, Commit: %s",
version.Version, version.BuildDate, version.CommitID)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
klog.Info("Shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
klog.Fatalf("Failed to shutdown server: %v", err)
}
}