feat usn sid 改成string

This commit is contained in:
2026-01-10 16:02:23 +08:00
parent e209ec64af
commit 8c6614578b
11 changed files with 43 additions and 49 deletions

View File

@@ -9,11 +9,11 @@ import (
)
type GrpcConnection struct {
sid int64
sid string
conn *grpc.ClientConn
}
func NewGrpcConnection(sid int64, address string) (*GrpcConnection, error) {
func NewGrpcConnection(sid string, address string) (*GrpcConnection, error) {
p := &GrpcConnection{
sid: sid,
}

View File

@@ -8,18 +8,18 @@ import (
)
type GrpcConnectionMgr struct {
poolM map[int64]*GrpcConnection
poolM map[string]*GrpcConnection
poolS []*GrpcConnection
}
func NewGrpcConnectionMgr() *GrpcConnectionMgr {
return &GrpcConnectionMgr{
poolM: make(map[int64]*GrpcConnection),
poolM: make(map[string]*GrpcConnection),
poolS: make([]*GrpcConnection, 0),
}
}
func (p *GrpcConnectionMgr) Store(sid int64, addr string) {
func (p *GrpcConnectionMgr) Store(sid string, addr string) {
pool, err := NewGrpcConnection(sid, addr)
if err != nil {
log.Errorf("create grpc err: %v, sid: %v, addr: %v", err, sid, addr)
@@ -29,7 +29,7 @@ func (p *GrpcConnectionMgr) Store(sid int64, addr string) {
p.poolS = append(p.poolS, pool)
}
func (p *GrpcConnectionMgr) Delete(sid int64) int {
func (p *GrpcConnectionMgr) Delete(sid string) int {
delete(p.poolM, sid)
for i, pool := range p.poolS {
if pool.sid == sid {
@@ -40,9 +40,9 @@ func (p *GrpcConnectionMgr) Delete(sid int64) int {
return len(p.poolS)
}
func (p *GrpcConnectionMgr) Load(sid ...int64) (*grpc.ClientConn, error) {
func (p *GrpcConnectionMgr) Load(sid ...string) (*grpc.ClientConn, error) {
var pool *GrpcConnection
if len(sid) > 0 && sid[0] > 0 {
if len(sid) > 0 && sid[0] != "" {
pool = p.poolM[sid[0]]
} else {
pool = p.poolS[rand.Intn(len(p.poolS))]
@@ -53,8 +53,8 @@ func (p *GrpcConnectionMgr) Load(sid ...int64) (*grpc.ClientConn, error) {
return pool.GetConnection(), nil
}
func (p *GrpcConnectionMgr) LoadAll() map[int64]*grpc.ClientConn {
sidM := make(map[int64]*grpc.ClientConn)
func (p *GrpcConnectionMgr) LoadAll() map[string]*grpc.ClientConn {
sidM := make(map[string]*grpc.ClientConn)
for sid, pool := range p.poolM {
sidM[sid] = pool.GetConnection()
}

View File

@@ -6,7 +6,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/proto/ss/grpc_pb"
)
func GatewayNewClient(sid ...int64) (grpc_pb.GatewayClient, error) {
func GatewayNewClient(sid ...string) (grpc_pb.GatewayClient, error) {
c, err := discover.FindServer(common.KeyDiscoverGateway, sid...)
if err != nil {
return nil, err
@@ -14,8 +14,8 @@ func GatewayNewClient(sid ...int64) (grpc_pb.GatewayClient, error) {
return grpc_pb.NewGatewayClient(c), nil
}
func GatewayNewBroadcastClient() map[int64]grpc_pb.GatewayClient {
clientM := make(map[int64]grpc_pb.GatewayClient)
func GatewayNewBroadcastClient() map[string]grpc_pb.GatewayClient {
clientM := make(map[string]grpc_pb.GatewayClient)
connM := discover.FindServerAll(common.KeyDiscoverGateway)
for sid, conn := range connM {
clientM[sid] = grpc_pb.NewGatewayClient(conn)

View File

@@ -7,7 +7,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/proto/ss/grpc_pb"
)
func SceneNewClient(sid ...int64) (grpc_pb.SceneClient, error) {
func SceneNewClient(sid ...string) (grpc_pb.SceneClient, error) {
c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
if err != nil {
return nil, err
@@ -23,8 +23,8 @@ func SceneNewClientLB() (grpc_pb.SceneClient, error) {
return grpc_pb.NewSceneClient(c), nil
}
func SceneNewBroadcastClient() map[int64]grpc_pb.SceneClient {
clientM := make(map[int64]grpc_pb.SceneClient)
func SceneNewBroadcastClient() map[string]grpc_pb.SceneClient {
clientM := make(map[string]grpc_pb.SceneClient)
connM := discover.FindServerAll(common.KeyDiscoverScene)
for sid, conn := range connM {
clientM[sid] = grpc_pb.NewSceneClient(conn)

View File

@@ -7,7 +7,7 @@ import (
"git.hlsq.asia/mmorpg/service-common/proto/ss/grpc_pb"
)
func UserNewClient(sid ...int64) (grpc_pb.UserClient, error) {
func UserNewClient(sid ...string) (grpc_pb.UserClient, error) {
c, err := discover.FindServer(common.KeyDiscoverUser, sid...)
if err != nil {
return nil, err

View File

@@ -22,7 +22,7 @@ type IService interface {
type Base struct {
Target string
SID int64
SID string
Serve *grpc.Server
EtcdTTL int64
OnInit func(serve *grpc.Server)
@@ -34,7 +34,7 @@ type Base struct {
func (s *Base) Init(addr string, port int32) {
s.wg = &sync.WaitGroup{}
s.wg.Add(1)
s.SID = utils.SnowflakeInstance().Generate().Int64()
s.SID = utils.SnowflakeInstance().Generate().String()
go func() {
defer s.wg.Done()
defer s.OnClose()