Skip to content

Commit e4d8332

Browse files
committed
fix 标识初始化
1 parent 3841b46 commit e4d8332

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

common/billing_packet.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,12 @@ func (packet *BillingPacket) String() string {
119119
"MsgID: [%x, %x]\n"+
120120
"Data: \n%s", packet.OpType, packet.MsgID[0], packet.MsgID[1], hex.Dump(packet.OpData))
121121
}
122+
123+
// InitBillingPacketHead 初始化头部标识
124+
func InitBillingPacketHead(billType byte) {
125+
if billType == BillTypeCommon {
126+
BillingPacketHead = [2]byte{0xAA, 0x55}
127+
} else if billType == BillTypeHuaiJiu {
128+
BillingPacketHead = [2]byte{0x55, 0xAA}
129+
}
130+
}

services/billing/run.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"os"
77
"os/signal"
88
"syscall"
9-
10-
"github.com/liuguangw/billing_go/common"
119
)
1210

1311
// Run 运行billing
@@ -29,12 +27,6 @@ func (s *Server) Run(logFilePath string) error {
2927
if err := s.initDatabase(); err != nil {
3028
s.logger.Fatal("init database connection failed: " + err.Error())
3129
}
32-
//初始化头部标识
33-
if s.config.BillType == common.BillTypeCommon {
34-
common.BillingPacketHead = [2]byte{0xAA, 0x55}
35-
} else if s.config.BillType == common.BillTypeHuaiJiu {
36-
common.BillingPacketHead = [2]byte{0x55, 0xAA}
37-
}
3830
//标记为已启动
3931
s.running = true
4032
s.logger.Info("billing server run at " + s.listener.Addr().String())

services/billing/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package billing
22

33
import (
44
"database/sql"
5+
"net"
6+
"os"
7+
58
"github.com/liuguangw/billing_go/common"
69
"github.com/liuguangw/billing_go/services"
710
"go.uber.org/zap"
8-
"net"
9-
"os"
1011
)
1112

1213
// Server billing 服务
@@ -27,6 +28,8 @@ func NewServer() (*Server, error) {
2728
if err != nil {
2829
return nil, err
2930
}
31+
//初始化头部标识
32+
common.InitBillingPacketHead(byte(serverConfig.BillType))
3033
return &Server{config: serverConfig}, nil
3134
}
3235

0 commit comments

Comments
 (0)