Skip to content

Commit 0cbf92e

Browse files
committed
adjust code
1 parent b72415c commit 0cbf92e

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

api/stream/connection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package stream
22

33
import (
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

89
func (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()
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ type ConnectionMGR struct {
119119
connections []*Connection
120120
}
121121

122-
var mgr *ConnectionMGR
122+
var cmgr *ConnectionMGR
123123

124124
func 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

135135
func (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
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package handler
1+
package connection
22

33
import (
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

2625
func 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

3534
func (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,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package handler
1+
package connection
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package handler
1+
package connection
22

33
import (
44
"context"

0 commit comments

Comments
 (0)