overflow_gateway_webapp/main.go

63 lines
1.3 KiB
Go
Raw Normal View History

2017-11-13 16:50:37 +00:00
package main
2017-11-14 03:45:48 +00:00
import (
2018-03-21 11:46:47 +00:00
"flag"
2017-11-14 03:45:48 +00:00
"os"
"os/signal"
"syscall"
2018-03-21 11:46:47 +00:00
cc "git.loafle.net/commons_go/config"
2017-11-14 03:45:48 +00:00
"git.loafle.net/commons_go/logging"
2018-03-21 11:46:47 +00:00
oocc "git.loafle.net/overflow/overflow_commons_go/config"
2017-11-14 03:45:48 +00:00
"git.loafle.net/overflow/overflow_gateway_webapp/server"
2017-11-28 11:08:46 +00:00
"git.loafle.net/overflow/overflow_gateway_webapp/servlet"
2018-03-21 11:46:47 +00:00
oogwc "git.loafle.net/overflow/overflow_gateway_websocket/config"
2017-11-14 03:45:48 +00:00
oogws "git.loafle.net/overflow/overflow_gateway_websocket/server"
)
2018-03-21 11:46:47 +00:00
var (
configDir *string
logConfigPath *string
)
func init() {
configDir = oocc.FlagConfigDir("./")
logConfigPath = oocc.FlagLogConfigFilePath("")
flag.Parse()
logging.InitializeLogger(*logConfigPath)
cc.SetConfigPath(*configDir)
if err := cc.Load(&oogwc.Config, oocc.ConfigFileName); nil != err {
logging.Logger().Panic(err)
}
}
2017-11-13 16:50:37 +00:00
func main() {
2017-11-14 03:45:48 +00:00
defer logging.Logger().Sync()
2017-11-28 11:08:46 +00:00
sh := server.NewServerHandler()
servlet.ServletInit(sh)
s := oogws.New(sh)
2017-11-14 03:45:48 +00:00
stop := make(chan os.Signal)
signal.Notify(stop, syscall.SIGINT)
go func() {
if err := s.Start(); nil != err {
2018-03-21 11:46:47 +00:00
logging.Logger().Infof("Server: Start error %v", err)
2017-11-14 03:45:48 +00:00
return
}
}()
select {
case signal := <-stop:
2018-03-21 11:46:47 +00:00
logging.Logger().Infof("Got signal: %v\n", signal)
2017-11-14 03:45:48 +00:00
}
2018-03-21 11:46:47 +00:00
servlet.ServletDestroy()
2017-11-14 03:45:48 +00:00
s.Stop()
2018-03-21 11:46:47 +00:00
logging.Logger().Infof("Server stopped")
2017-11-13 16:50:37 +00:00
}