From 637cdaca2489e3e7e33e34ccec1af2aaec840ee1 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 10 Apr 2018 15:03:15 +0900 Subject: [PATCH] ing --- config.json | 10 ++++++++++ config/config.go | 6 ++++-- main.go | 6 +++--- server/server-handler.go | 9 ++++++++- server/server.go | 9 +++++++-- subscribe/subscribe.go | 12 ++++++------ 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/config.json b/config.json index c56db16..0cc146f 100644 --- a/config.json +++ b/config.json @@ -15,5 +15,15 @@ "pingTimeout": 10, "pingPeriod": 10, "enableCompression": false + }, + "external": { + "grpc": { + "network": "tcp4", + "address": "192.168.1.50:50006" + }, + "redis": { + "network": "tcp4", + "address": "192.168.1.50:6379" + } } } diff --git a/config/config.go b/config/config.go index c1bd103..fd05c5c 100644 --- a/config/config.go +++ b/config/config.go @@ -1,9 +1,11 @@ package config import ( - "git.loafle.net/commons/server-go/socket/web" + occe "git.loafle.net/overflow/commons-go/config/external" + ogrs "git.loafle.net/overflow/gateway_rpc/server" ) type Config struct { - ServerHandler web.ServerHandlers `json:"serverHandler"` + ServerHandler *ogrs.ServerHandlers `json:"serverHandler"` + External *occe.External `json:"external"` } diff --git a/main.go b/main.go index f8a4851..c35b5fa 100644 --- a/main.go +++ b/main.go @@ -28,13 +28,13 @@ func init() { } func main() { - config := &config.Config{} + _config := &config.Config{} configuration.SetConfigPath(*configDir) - if err := configuration.Load(config, "config.json"); nil != err { + if err := configuration.Load(_config, "config.json"); nil != err { logging.Logger().Panic(err) } - s := server.New() + s := server.New(_config) go func() { err := s.ListenAndServe() diff --git a/server/server-handler.go b/server/server-handler.go index 29356b9..2297a2d 100644 --- a/server/server-handler.go +++ b/server/server-handler.go @@ -2,7 +2,9 @@ package server import ( cs "git.loafle.net/commons/server-go" + oge "git.loafle.net/overflow/gateway/external" ogrs "git.loafle.net/overflow/gateway_rpc/server" + "git.loafle.net/overflow/member_gateway_rpc/config" "git.loafle.net/overflow/member_gateway_rpc/subscribe" ) @@ -12,13 +14,15 @@ type ServerHandler interface { type ServerHandlers struct { ogrs.ServerHandlers + + Config *config.Config } func (sh *ServerHandlers) Init(serverCtx cs.ServerCtx) error { if err := sh.ServerHandlers.Init(serverCtx); nil != err { return err } - + oge.InitPackage(sh.Config.External) subscribe.InitPackage() return nil @@ -29,6 +33,7 @@ func (sh *ServerHandlers) OnStart(serverCtx cs.ServerCtx) error { return err } + oge.StartPackage(sh.Config.External) subscribe.StartPackage() return nil @@ -36,12 +41,14 @@ func (sh *ServerHandlers) OnStart(serverCtx cs.ServerCtx) error { func (sh *ServerHandlers) OnStop(serverCtx cs.ServerCtx) { subscribe.StopPackage() + oge.StopPackage(sh.Config.External) sh.ServerHandlers.OnStop(serverCtx) } func (sh *ServerHandlers) Destroy(serverCtx cs.ServerCtx) { subscribe.DestroyPackage() + oge.DestroyPackage(sh.Config.External) sh.ServerHandlers.Destroy(serverCtx) } diff --git a/server/server.go b/server/server.go index 25bce2a..33b10be 100644 --- a/server/server.go +++ b/server/server.go @@ -2,12 +2,17 @@ package server import ( csgw "git.loafle.net/commons/server-go/socket/web" + "git.loafle.net/overflow/member_gateway_rpc/config" "git.loafle.net/overflow/member_gateway_rpc/servlet" ) -func New() *csgw.Server { +func New(_config *config.Config) *csgw.Server { ws := &servlet.WebappServlets{} - sh := &ServerHandlers{} + sh := &ServerHandlers{ + ServerHandlers: *_config.ServerHandler, + Config: _config, + } + sh.RegisterServlet("/webapp", ws) s := &csgw.Server{ diff --git a/subscribe/subscribe.go b/subscribe/subscribe.go index e39e8f3..1ea2ed8 100644 --- a/subscribe/subscribe.go +++ b/subscribe/subscribe.go @@ -10,23 +10,23 @@ var Subscriber *ogsr.Subscribers func InitPackage() { Subscriber = &ogsr.Subscribers{} -} - -func StartPackage() { Subscriber.Conn = oger.Pool.Get() if err := Subscriber.Start(); nil != err { logging.Logger().Panic(err) } } +func StartPackage() { +} + func StopPackage() { +} + +func DestroyPackage() { if nil != Subscriber { if err := Subscriber.Stop(); nil != err { logging.Logger().Error(err) } } -} - -func DestroyPackage() { Subscriber = nil }