probe_gateway_rpc/main.go

62 lines
1.2 KiB
Go
Raw Normal View History

2018-04-12 12:07:02 +00:00
package main
import (
2018-04-12 12:39:48 +00:00
"context"
"flag"
2018-04-12 12:07:02 +00:00
"log"
"os"
"os/signal"
"syscall"
"time"
2018-04-12 12:39:48 +00:00
2018-04-12 12:07:02 +00:00
"git.loafle.net/commons/configuration-go"
2018-04-12 12:39:48 +00:00
"git.loafle.net/commons/logging-go"
2018-04-26 08:17:12 +00:00
"git.loafle.net/overflow/probe_gateway_rpc/config"
2018-04-12 12:39:48 +00:00
"git.loafle.net/overflow/probe_gateway_rpc/server"
2018-04-12 12:07:02 +00:00
)
var (
configDir *string
)
func init() {
configDir = flag.String("config-dir", "./", "Config directory")
logConfigPath := flag.String("log-config", "", "logging config path")
flag.Parse()
logging.InitializeLogger(*logConfigPath)
}
func main() {
_config := &config.Config{}
configuration.SetConfigPath(*configDir)
if err := configuration.Load(_config, "config.json"); nil != err {
logging.Logger().Panic(err)
}
s := server.New(_config)
go func() {
err := s.ListenAndServe()
if nil != err {
log.Printf("err: %v", err)
}
}()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt,
syscall.SIGKILL,
syscall.SIGSTOP,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
logging.Logger().Errorf("error: %v", err)
}
}