From 18845c4ff9adc6240435fe01f40d3181107b0469 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 22 Mar 2018 18:15:12 +0900 Subject: [PATCH] ing --- main.go | 32 ++++++++++++++++++++++----- servlet/auth/auth.go | 4 +--- servlet/data/data.go | 4 +--- servlet/probe/gateway_rpc_handlers.go | 2 +- servlet/probe/probe.go | 4 +--- servlet/probe/subscriber_handlers.go | 4 +--- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index a224553..3ceec41 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,40 @@ package main import ( - "fmt" - "log" + "flag" "os" "os/signal" "syscall" + cc "git.loafle.net/commons_go/config" "git.loafle.net/commons_go/logging" + oocc "git.loafle.net/overflow/overflow_commons_go/config" "git.loafle.net/overflow/overflow_gateway_probe/server" "git.loafle.net/overflow/overflow_gateway_probe/servlet" + oogwc "git.loafle.net/overflow/overflow_gateway_websocket/config" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" ) -func main() { +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) + } + +} + +func main() { defer logging.Logger().Sync() sh := server.NewServerHandler() @@ -27,17 +47,19 @@ func main() { go func() { if err := s.Start(); nil != err { - log.Printf("Server: Start error %v", err) + logging.Logger().Infof("Server: Start error %v", err) return } }() select { case signal := <-stop: - fmt.Printf("Got signal: %v\n", signal) + logging.Logger().Infof("Got signal: %v", signal) } servlet.ServletDestroy() s.Stop() + + logging.Logger().Infof("Server stopped") } diff --git a/servlet/auth/auth.go b/servlet/auth/auth.go index 5e1ea77..ce876cb 100644 --- a/servlet/auth/auth.go +++ b/servlet/auth/auth.go @@ -1,8 +1,6 @@ package auth import ( - "fmt" - "git.loafle.net/commons_go/logging" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/config" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" @@ -20,7 +18,7 @@ var ( func ServletInit(sh oogws.ServerHandler) { cfg = oogwc.Config.Servlets[Name] if nil == cfg { - logging.Logger().Panic(fmt.Sprintf("Webapp: config of servlet[%s] is not exist", Name)) + logging.Logger().Panicf("Webapp: config of servlet[%s] is not exist", Name) } rpcGH := newGatewayRPCHandler() diff --git a/servlet/data/data.go b/servlet/data/data.go index fe6e428..5043faf 100644 --- a/servlet/data/data.go +++ b/servlet/data/data.go @@ -1,8 +1,6 @@ package data import ( - "fmt" - "git.loafle.net/commons_go/logging" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/config" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" @@ -20,7 +18,7 @@ var ( func ServletInit(sh oogws.ServerHandler) { cfg = oogwc.Config.Servlets[Name] if nil == cfg { - logging.Logger().Panic(fmt.Sprintf("Webapp: config of servlet[%s] is not exist", Name)) + logging.Logger().Panicf("Webapp: config of servlet[%s] is not exist", Name) } rpcGH := newGatewayRPCHandler() diff --git a/servlet/probe/gateway_rpc_handlers.go b/servlet/probe/gateway_rpc_handlers.go index 322811e..2dde15a 100644 --- a/servlet/probe/gateway_rpc_handlers.go +++ b/servlet/probe/gateway_rpc_handlers.go @@ -60,7 +60,7 @@ func (sh *GatewayRPCHandlers) Handshake(socketCTX cwf.SocketContext, ctx *fastht // var claims jwt.MapClaims // if claims, ok = token.Claims.(jwt.MapClaims); !ok || !token.Valid { - // logging.Logger().Warn(fmt.Sprintf("Webapp: Token is not valid %v", token)) + // logging.Logger().Warnf("Webapp: Token is not valid %v", token) // return "", nil // } bProbeKey := ctx.Request.Header.Peek(oocmp.HTTPRequestHeaderKey_Probe_ProbeKey) diff --git a/servlet/probe/probe.go b/servlet/probe/probe.go index c61bba8..515b07e 100644 --- a/servlet/probe/probe.go +++ b/servlet/probe/probe.go @@ -1,8 +1,6 @@ package probe import ( - "fmt" - "git.loafle.net/commons_go/logging" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/config" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" @@ -20,7 +18,7 @@ var ( func ServletInit(sh oogws.ServerHandler) { cfg = oogwc.Config.Servlets[Name] if nil == cfg { - logging.Logger().Panic(fmt.Sprintf("Webapp: config of servlet[%s] is not exist", Name)) + logging.Logger().Panicf("Webapp: config of servlet[%s] is not exist", Name) } rpcGH := newGatewayRPCHandler() diff --git a/servlet/probe/subscriber_handlers.go b/servlet/probe/subscriber_handlers.go index 56ce0c4..30931a8 100644 --- a/servlet/probe/subscriber_handlers.go +++ b/servlet/probe/subscriber_handlers.go @@ -1,8 +1,6 @@ package probe import ( - "fmt" - "git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/websocket_fasthttp/websocket" oogws "git.loafle.net/overflow/overflow_gateway_websocket/servlet" @@ -31,7 +29,7 @@ func (sh *SubscriberHandlers) OnSubscribe(channel string, message oos.SubscribeM } } default: - logging.Logger().Warn(fmt.Sprintf("[PROBE] SubscriberHandler: Unknown TargetType %s", message.TargetType)) + logging.Logger().Warnf("[PROBE] SubscriberHandler: Unknown TargetType %s", message.TargetType) } }