-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (40 loc) · 896 Bytes
/
main.go
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
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
log "atbmarket.comfaceapp/app_logger"
"atbmarket.comfaceapp/config"
"atbmarket.comfaceapp/handlers"
"go.uber.org/zap"
)
func main() {
// Config logger
conf := config.GetConfig()
wait := time.Second * 2
log.Logger.Info("Current environment", zap.String("Config", fmt.Sprintf("%v", conf)))
router := handlers.NewRouter()
srv := &http.Server{
Addr: ":" + conf.TCP_Port,
Handler: router,
}
go func() {
if err := srv.ListenAndServe(); err != nil {
panic(err)
}
log.Logger.Info("Listen is started")
}()
// Listen for os sygnals
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
//Grasefun shutdown
log.Logger.Info("Star server Shutdown on system sygnal")
ctx, cancel := context.WithTimeout(context.Background(), wait)
defer cancel()
srv.Shutdown(ctx)
os.Exit(0)
}