File tree Expand file tree Collapse file tree 5 files changed +25
-17
lines changed
Expand file tree Collapse file tree 5 files changed +25
-17
lines changed Original file line number Diff line number Diff line change 11package stream
22
33import (
4+ "github.com/NpoolPlatform/go-service-framework/pkg/logger"
45 "github.com/NpoolPlatform/message/npool/sphinxproxy"
56 "github.com/NpoolPlatform/sphinx-proxy/pkg/connection"
67)
78
89func (s * Server ) ProxyConnnection (stream sphinxproxy.SphinxProxyStream_ProxyConnnectionServer ) error {
910 conn , err := connection .RegisterConnection (stream )
1011 if err != nil {
12+ logger .Sugar ().Error (err )
1113 return err
1214 }
1315 defer conn .Close ()
Original file line number Diff line number Diff line change @@ -119,17 +119,17 @@ type ConnectionMGR struct {
119119 connections []* Connection
120120}
121121
122- var mgr * ConnectionMGR
122+ var cmgr * ConnectionMGR
123123
124124func GetConnectionMGR () * ConnectionMGR {
125- if mgr == nil {
126- mgr = & ConnectionMGR {
125+ if cmgr == nil {
126+ cmgr = & ConnectionMGR {
127127 siderInfos : make (map [string ]* sphinxproxy.SiderInfo ),
128128 connInfos : make (map [string ]map [sphinxproxy.SiderType ][]* Connection ),
129129 recvChannel : sync.Map {},
130130 }
131131 }
132- return mgr
132+ return cmgr
133133}
134134
135135func (mgr * ConnectionMGR ) AddConnection (conn * Connection ) {
@@ -321,8 +321,15 @@ func (mgr *ConnectionMGR) DealDataElement(data *sphinxproxy.DataElement) {
321321 }:
322322 }
323323 }
324- logger .Sugar ().Warn (data )
325324
326- err := mgr .ReplyMsg (data , & MsgInfo {Payload : []byte (fmt .Sprintf ("proxy reply for :%v" , string (data .Payload )))})
327- logger .Sugar ().Error (err )
325+ handler , err := GetDEHandlerMGR ().GetDEHandler (data .MsgType )
326+ if err != nil {
327+ logger .Sugar ().Error (err )
328+ return
329+ }
330+
331+ err = handler (data )
332+ if err != nil {
333+ logger .Sugar ().Error (err )
334+ }
328335}
Original file line number Diff line number Diff line change 1- package handler
1+ package connection
22
33import (
44 "context"
55 "encoding/json"
66 "fmt"
77
88 "github.com/NpoolPlatform/message/npool/sphinxproxy"
9- "github.com/NpoolPlatform/sphinx-proxy/pkg/connection"
109 "github.com/NpoolPlatform/sphinx-proxy/pkg/utils"
1110)
1211
@@ -21,15 +20,15 @@ type DEHandlerMGR struct {
2120 DEHandlers map [sphinxproxy.MsgType ]* DEHandler
2221}
2322
24- var mgr * DEHandlerMGR
23+ var hmgr * DEHandlerMGR
2524
2625func GetDEHandlerMGR () * DEHandlerMGR {
27- if mgr == nil {
28- mgr = & DEHandlerMGR {
26+ if hmgr == nil {
27+ hmgr = & DEHandlerMGR {
2928 DEHandlers : make (map [sphinxproxy.MsgType ]* DEHandler ),
3029 }
3130 }
32- return mgr
31+ return hmgr
3332}
3433
3534func (mgr * DEHandlerMGR ) RegisterDEHandler (
@@ -67,9 +66,9 @@ func (mgr *DEHandlerMGR) RegisterDEHandler(
6766 statusMsg = err .Error ()
6867 }
6968
70- return connection . GetConnectionMGR ().ReplyMsg (
69+ return GetConnectionMGR ().ReplyMsg (
7170 data ,
72- & connection. MsgInfo {
71+ & MsgInfo {
7372 Payload : outPayload ,
7473 StatusCode : statusCode ,
7574 StatusMsg : & statusMsg ,
Original file line number Diff line number Diff line change 1- package handler
1+ package connection
22
33import (
44 "context"
Original file line number Diff line number Diff line change 1- package handler
1+ package connection
22
33import (
44 "context"
You can’t perform that action at this time.
0 commit comments