-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (37 loc) · 810 Bytes
/
main.go
File metadata and controls
44 lines (37 loc) · 810 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
44
package main
import (
"github.com/rs/zerolog/log"
"grpc-gateway-example/config"
"grpc-gateway-example/handler"
"grpc-gateway-example/server"
"os"
"os/signal"
"syscall"
)
func run() {
cfg := config.Init()
h, err := handler.New(cfg)
if err != nil {
log.Fatal().Err(err).Msg("failed to make new handler")
}
grpcServer, err := server.NewGRPCServer(h)
if err != nil {
log.Fatal().Err(err).Msg("NewGRPCServer failed")
}
go grpcServer.ServeGRPC()
go server.ServeHTTP()
done := make(chan bool, 1)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM, syscall.SIGINT)
go stop(quit, done)
log.Info().Msg("starting server...")
<-done
}
func stop(quit <-chan os.Signal, done chan<- bool) {
<-quit
log.Info().Msg("stopping server...")
close(done)
}
func main() {
run()
}