/
main.go
55 lines (44 loc) · 1.46 KB
/
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
47
48
49
50
51
52
53
54
55
// Package main provides the main function of the trigger
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"
_ "go.uber.org/automaxprocs"
"github.com/beihai0xff/pudding/app/trigger/server"
"github.com/beihai0xff/pudding/configs"
"github.com/beihai0xff/pudding/pkg/log"
"github.com/beihai0xff/pudding/pkg/shutdown"
"github.com/beihai0xff/pudding/pkg/tls"
)
func main() {
// TODO: add flags
// mysqlDSN := flag.String("mysql-url", "", "The server mysql connection dsn")
// webhookPrefix := flag.String("webhook-prefix", "", "The server webhook prefix")
flag.Parse()
conf := configs.ParseTriggerConfig(*configs.GetConfigFilePath())
tls.New(conf.BaseConfig.HostDomain, conf.BaseConfig.TLS)
server.RegisterLogger()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(interrupt)
// start server
grpcServer, healthcheck, httpServer := server.StartServer(conf)
// register service to consul
resolverPairs := server.RegisterResolver(conf)
// block until a signal is received.
sign := <-interrupt
log.Warnf("received shutdown signal: %s", sign.String())
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
shutdown.GracefulShutdown(ctx,
shutdown.ResolverDeregister(resolverPairs...),
shutdown.HealthServerShutdown(healthcheck),
shutdown.HTTPServerShutdown(httpServer),
shutdown.GRPCServerShutdown(grpcServer),
shutdown.LogSync(),
)
}