-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (35 loc) · 974 Bytes
/
main.go
File metadata and controls
43 lines (35 loc) · 974 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/me2seeks/cola/config"
"github.com/me2seeks/cola/internal/pkg/logger"
"github.com/me2seeks/cola/internal/router"
)
func main() {
server := &http.Server{
Addr: config.Cfg.Host + ":" + strconv.Itoa(config.Cfg.Port),
Handler: router.Router,
}
logger.Logger.Printf("Server is running on port %d", config.Cfg.Port)
go func() {
if err := server.ListenAndServe(); err != nil {
logger.Logger.Fatalf("Server failed to start: %v", err)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
i := <-quit
logger.Logger.Println("server receive a signal: ", i.String())
ctx, canecl := context.WithTimeout(context.Background(), 5*time.Second)
defer canecl()
if err := server.Shutdown(ctx); err != nil {
logger.Logger.Fatalf("Server failed to shutdown: %v", err)
}
logger.Logger.Println("Server shutdown")
}