-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (41 loc) · 1.01 KB
/
main.go
File metadata and controls
51 lines (41 loc) · 1.01 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
package main
import (
"context"
"flag"
"net/http"
"os/signal"
"syscall"
"time"
"github.com/golang/glog"
"meow-ai/config"
"meow-ai/server"
)
func main() {
_ = flag.Set("logtostderr", "true")
flag.Parse()
cfg := config.MustLoad("config.yaml")
handler := server.NewHandler(cfg)
mux := http.NewServeMux()
handler.Register(mux)
srv := &http.Server{
Addr: cfg.Addr(),
Handler: mux,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 60 * time.Second,
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
go func() {
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := srv.Shutdown(shutdownCtx); err != nil {
glog.Warningf("server shutdown error: %v", err)
}
}()
glog.Infof("server listening on %s", cfg.Addr())
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
glog.Fatalf("server error: %v", err)
}
}