diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..fd05c5c --- /dev/null +++ b/config/config.go @@ -0,0 +1,11 @@ +package config + +import ( + occe "git.loafle.net/overflow/commons-go/config/external" + ogrs "git.loafle.net/overflow/gateway_rpc/server" +) + +type Config struct { + ServerHandler *ogrs.ServerHandlers `json:"serverHandler"` + External *occe.External `json:"external"` +} diff --git a/main.go b/main.go index 5dc1f44..5e685b1 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "git.loafle.net/commons/configuration-go" "git.loafle.net/commons/logging-go" - "git.loafle.net/overflow/member_gateway_rpc/config" + "git.loafle.net/overflow/probe_gateway_rpc/config" "git.loafle.net/overflow/probe_gateway_rpc/server" ) diff --git a/server/server-handler.go b/server/server-handler.go index 2297a2d..4212858 100644 --- a/server/server-handler.go +++ b/server/server-handler.go @@ -4,8 +4,8 @@ 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" + "git.loafle.net/overflow/probe_gateway_rpc/config" + "git.loafle.net/overflow/probe_gateway_rpc/subscribe" ) type ServerHandler interface { diff --git a/server/server.go b/server/server.go index 4500bd4..924b87d 100644 --- a/server/server.go +++ b/server/server.go @@ -2,7 +2,7 @@ package server import ( cssw "git.loafle.net/commons/server-go/socket/web" - "git.loafle.net/overflow/member_gateway_rpc/config" + "git.loafle.net/overflow/probe_gateway_rpc/config" "git.loafle.net/overflow/probe_gateway_rpc/servlet" ) diff --git a/servlet/auth-servlet.go b/servlet/auth-servlet.go index c36a0d9..c1cf0e7 100644 --- a/servlet/auth-servlet.go +++ b/servlet/auth-servlet.go @@ -11,13 +11,13 @@ import ( "git.loafle.net/commons/logging-go" "git.loafle.net/commons/server-go" "git.loafle.net/commons/server-go/socket" - ocnc "git.loafle.net/overflow/commons-go/noauthprobe/constants" - ocnm "git.loafle.net/overflow/commons-go/noauthprobe/model" + occn "git.loafle.net/overflow/commons-go/config/noauthprobe" + ocmn "git.loafle.net/overflow/commons-go/model/noauthprobe" og "git.loafle.net/overflow/gateway" "git.loafle.net/overflow/gateway/external/grpc" ogs "git.loafle.net/overflow/gateway/subscribe" ogrs "git.loafle.net/overflow/gateway_rpc/servlet" - "git.loafle.net/overflow/member_gateway_rpc/subscribe" + "git.loafle.net/overflow/probe_gateway_rpc/subscribe" ) type AuthServlet interface { @@ -41,7 +41,7 @@ func (s *AuthServlets) OnStart(serverCtx server.ServerCtx) error { return err } - subscribeChan, err := subscribe.Subscriber.Subscribe(ocnc.HTTPEntry_Auth) + subscribeChan, err := subscribe.Subscriber.Subscribe(occn.HTTPEntry_Auth) if nil != err { return err } @@ -51,7 +51,7 @@ func (s *AuthServlets) OnStart(serverCtx server.ServerCtx) error { } func (s *AuthServlets) OnStop(serverCtx server.ServerCtx) { - if err := subscribe.Subscriber.Unsubscribe(ocnc.HTTPEntry_Auth); nil != err { + if err := subscribe.Subscriber.Unsubscribe(occn.HTTPEntry_Auth); nil != err { logging.Logger().Warn(err) } @@ -64,7 +64,7 @@ func (s *AuthServlets) Destroy(serverCtx server.ServerCtx) { } func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) { - bMethod := ctx.Request.Header.Peek(ocnc.HTTPRequestHeaderKey_NoAuthProbe_Method) + bMethod := ctx.Request.Header.Peek(occn.HTTPRequestHeaderKey_NoAuthProbe_Method) if nil == bMethod { return nil, fmt.Errorf("Unexpected noauth probe method: %v", bMethod) @@ -73,8 +73,8 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req method := string(bMethod) switch method { - case ocnc.HTTPRequestHeaderValue_NoAuthProbe_Method_Regist: - bInfo := ctx.Request.Header.Peek(ocnc.HTTPRequestHeaderKey_NoAuthProbe_Info) + case occn.HTTPRequestHeaderValue_NoAuthProbe_Method_Regist: + bInfo := ctx.Request.Header.Peek(occn.HTTPRequestHeaderKey_NoAuthProbe_Info) if nil == bInfo { return nil, fmt.Errorf("Unexpected Request Header Key NoAuthProbe Info") } @@ -89,22 +89,22 @@ func (s *AuthServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req if nil != err { return nil, fmt.Errorf("grpc call Error: %s", err.Error()) } - nap := &ocnm.NoAuthProbe{} + nap := &ocmn.NoAuthProbe{} err = json.Unmarshal([]byte(r), nap) if nil != err { return nil, fmt.Errorf("grpc result unMarshal Error: %s", err.Error()) } extHeader := &fasthttp.ResponseHeader{} - extHeader.Add(ocnc.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey, nap.TempProbeKey) + extHeader.Add(occn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey, nap.TempProbeKey) servletCtx.SetAttribute(og.SessionIDKey, nap.TempProbeKey) servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE) servletCtx.SetAttribute(og.SessionTargetIDKey, nap.TempProbeKey) return extHeader, nil - case ocnc.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect: - bTempProbeKey := ctx.Request.Header.Peek(ocnc.HTTPRequestHeaderKey_NoAuthProbe_TempProbeKey) + case occn.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect: + bTempProbeKey := ctx.Request.Header.Peek(occn.HTTPRequestHeaderKey_NoAuthProbe_TempProbeKey) if nil == bTempProbeKey { return nil, fmt.Errorf("Noauth probe temp key is not an existing key") } diff --git a/servlet/data-servlet.go b/servlet/data-servlet.go index 90c7290..186397a 100644 --- a/servlet/data-servlet.go +++ b/servlet/data-servlet.go @@ -10,7 +10,7 @@ import ( "git.loafle.net/commons/server-go" "git.loafle.net/commons/server-go/socket" - ocpc "git.loafle.net/overflow/commons-go/probe/constants" + occp "git.loafle.net/overflow/commons-go/config/probe" og "git.loafle.net/overflow/gateway" "git.loafle.net/overflow/gateway/external/grpc" ogrs "git.loafle.net/overflow/gateway_rpc/servlet" @@ -57,7 +57,7 @@ func (s *DataServlets) Destroy(serverCtx server.ServerCtx) { func (s *DataServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) { // probe key extraction - bMethod := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_Method) + bMethod := ctx.Request.Header.Peek(occp.HTTPRequestHeaderKey_Probe_Method) if nil == bMethod { return nil, fmt.Errorf("Unexpected probe method: %v", bMethod) } @@ -65,12 +65,12 @@ func (s *DataServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Req method := string(bMethod) switch method { - case ocpc.HTTPRequestHeaderValue_Probe_Method_Connect: + case occp.HTTPRequestHeaderValue_Probe_Method_Connect: default: return nil, fmt.Errorf("Unexpected probe method: %s", method) } - bProbeKey := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_ProbeKey) + bProbeKey := ctx.Request.Header.Peek(occp.HTTPRequestHeaderKey_Probe_ProbeKey) if nil == bProbeKey { return nil, fmt.Errorf("Unexpected probe key : %v", bProbeKey) } diff --git a/servlet/probe-servlet.go b/servlet/probe-servlet.go index 5f6a15c..4714f35 100644 --- a/servlet/probe-servlet.go +++ b/servlet/probe-servlet.go @@ -10,13 +10,13 @@ import ( "git.loafle.net/commons/logging-go" "git.loafle.net/commons/server-go" "git.loafle.net/commons/server-go/socket" - ocpc "git.loafle.net/overflow/commons-go/probe/constants" - ocpm "git.loafle.net/overflow/commons-go/probe/model" + occp "git.loafle.net/overflow/commons-go/config/probe" + ocmp "git.loafle.net/overflow/commons-go/model/probe" og "git.loafle.net/overflow/gateway" "git.loafle.net/overflow/gateway/external/grpc" ogs "git.loafle.net/overflow/gateway/subscribe" ogrs "git.loafle.net/overflow/gateway_rpc/servlet" - "git.loafle.net/overflow/member_gateway_rpc/subscribe" + "git.loafle.net/overflow/probe_gateway_rpc/subscribe" ) type ProbeServlet interface { @@ -40,7 +40,7 @@ func (s *ProbeServlets) OnStart(serverCtx server.ServerCtx) error { return err } - subscribeChan, err := subscribe.Subscriber.Subscribe(ocpc.HTTPEntry_Probe) + subscribeChan, err := subscribe.Subscriber.Subscribe(occp.HTTPEntry_Probe) if nil != err { return err } @@ -50,7 +50,7 @@ func (s *ProbeServlets) OnStart(serverCtx server.ServerCtx) error { } func (s *ProbeServlets) OnStop(serverCtx server.ServerCtx) { - if err := subscribe.Subscriber.Unsubscribe(ocpc.HTTPEntry_Probe); nil != err { + if err := subscribe.Subscriber.Unsubscribe(occp.HTTPEntry_Probe); nil != err { logging.Logger().Warn(err) } @@ -63,7 +63,7 @@ func (s *ProbeServlets) Destroy(serverCtx server.ServerCtx) { } func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) (*fasthttp.ResponseHeader, error) { - bMethod := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_Method) + bMethod := ctx.Request.Header.Peek(occp.HTTPRequestHeaderKey_Probe_Method) if nil == bMethod { return nil, fmt.Errorf("Unexpected probe method: %v", bMethod) } @@ -71,12 +71,12 @@ func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Re method := string(bMethod) switch method { - case ocpc.HTTPRequestHeaderValue_Probe_Method_Connect: + case occp.HTTPRequestHeaderValue_Probe_Method_Connect: default: return nil, fmt.Errorf("Unexpected probe method: %s", method) } - bProbeKey := ctx.Request.Header.Peek(ocpc.HTTPRequestHeaderKey_Probe_ProbeKey) + bProbeKey := ctx.Request.Header.Peek(occp.HTTPRequestHeaderKey_Probe_ProbeKey) if nil == bProbeKey { return nil, fmt.Errorf("Unexpected probe key : %v", bProbeKey) } @@ -89,14 +89,14 @@ func (s *ProbeServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.Re return nil, fmt.Errorf("grpc call Error: %s", err.Error()) } - probe := &ocpm.Probe{} + probe := &ocmp.Probe{} err = json.Unmarshal([]byte(r), probe) if nil != err { return nil, fmt.Errorf("grpc result unMarshal Error: %s", err.Error()) } extHeader := &fasthttp.ResponseHeader{} - extHeader.Add(ocpc.HTTPResponseHeaderKey_Probe_SetEncryptionKey, probe.EncryptionKey) + extHeader.Add(occp.HTTPResponseHeaderKey_Probe_SetEncryptionKey, probe.EncryptionKey) servletCtx.SetAttribute(og.SessionIDKey, probeKey) servletCtx.SetAttribute(og.SessionClientTypeKey, og.PROBE) diff --git a/subscribe/subscribe.go b/subscribe/subscribe.go new file mode 100644 index 0000000..1ea2ed8 --- /dev/null +++ b/subscribe/subscribe.go @@ -0,0 +1,32 @@ +package subscribe + +import ( + "git.loafle.net/commons/logging-go" + oger "git.loafle.net/overflow/gateway/external/redis" + ogsr "git.loafle.net/overflow/gateway/subscribe/redis" +) + +var Subscriber *ogsr.Subscribers + +func InitPackage() { + Subscriber = &ogsr.Subscribers{} + 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) + } + } + Subscriber = nil +}