feat 初始化
This commit is contained in:
@@ -5,18 +5,17 @@ import (
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func AdminNewClient(sid ...int64) (rspb.AdminClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverAdmin, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewAdminClient(c), nil
|
||||
}
|
||||
|
||||
func AdminNewClientLB() (rspb.AdminClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameAdmin)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameAdmin)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverAdmin, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
)
|
||||
|
||||
func AnnouncementNewClient(sid ...int64) (rspb.AnnouncementClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverAnnouncement, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewAnnouncementClient(c), nil
|
||||
}
|
||||
|
||||
func AnnouncementNewClientLB() (rspb.AnnouncementClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameAnnouncement)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewAnnouncementClient(c), nil
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
)
|
||||
|
||||
func CourtPhysicalNewClient(sid ...int64) (rspb.CourtPhysicalClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverCourtPhysical, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewCourtPhysicalClient(c), nil
|
||||
}
|
||||
|
||||
func CourtPhysicalNewClientLB() (rspb.CourtPhysicalClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameCourtPhysical)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewCourtPhysicalClient(c), nil
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
)
|
||||
|
||||
func CourtNewClient(sid ...int64) (rspb.CourtClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverCourt, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewCourtClient(c), nil
|
||||
}
|
||||
|
||||
func CourtNewClientLB() (rspb.CourtClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameCourt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewCourtClient(c), nil
|
||||
}
|
||||
@@ -4,10 +4,18 @@ import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func GatewayNewClient(sid ...int64) (rspb.GatewayClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverGateway, sid...)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameGateway)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverGateway, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
23
net/grpc/grpcclient/client_notice.go
Normal file
23
net/grpc/grpcclient/client_notice.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NoticeNewClient(sid ...int64) (rspb.NoticeClient, error) {
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameNotice)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverNotice, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewNoticeClient(c), nil
|
||||
}
|
||||
@@ -5,18 +5,17 @@ import (
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func PostNewClient(sid ...int64) (rspb.PostClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverPost, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewPostClient(c), nil
|
||||
}
|
||||
|
||||
func PostNewClientLB() (rspb.PostClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNamePost)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNamePost)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverPost, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func QgdzsNewClient(sid ...int64) (rspb.QgdzsClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverQgdzs, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewQgdzsClient(c), nil
|
||||
}
|
||||
|
||||
func QgdzsNewClientLB() (rspb.QgdzsClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameQgdzs)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameQgdzs)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverQgdzs, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,11 +6,18 @@ import (
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// SceneNewClient 根据SID查找场景服,一般不用这个函数
|
||||
func SceneNewClient(sid ...int64) (rspb.SceneClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverScene, sid...)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameScene)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverScene, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -26,14 +33,6 @@ func SceneInstanceNewClient(uniqueNO int64) (rspb.SceneClient, error) {
|
||||
return SceneNewClient(sid)
|
||||
}
|
||||
|
||||
func SceneNewClientLB() (rspb.SceneClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameScene)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewSceneClient(c), nil
|
||||
}
|
||||
|
||||
func SceneNewBroadcastClient() map[int64]rspb.SceneClient {
|
||||
clientM := make(map[int64]rspb.SceneClient)
|
||||
connM := discover.FindServerAll(common.KeyDiscoverScene)
|
||||
|
||||
@@ -5,18 +5,17 @@ import (
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func ThirdPartyNewClient(sid ...int64) (rspb.ThirdPartyClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverThirdParty, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewThirdPartyClient(c), nil
|
||||
}
|
||||
|
||||
func ThirdPartyNewClientLB() (rspb.ThirdPartyClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameThirdParty)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameThirdParty)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverThirdParty, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
23
net/grpc/grpcclient/client_timer.go
Normal file
23
net/grpc/grpcclient/client_timer.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rspb"
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TimerNewClient(sid ...int64) (rspb.TimerClient, error) {
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameTimer)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverTimer, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewTimerClient(c), nil
|
||||
}
|
||||
@@ -5,18 +5,17 @@ import (
|
||||
"git.hlsq.asia/alex/service-common/discover"
|
||||
"git.hlsq.asia/alex/service-common/discover/common"
|
||||
"git.hlsq.asia/alex/service-common/net/grpc/resolver"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func UserNewClient(sid ...int64) (rspb.UserClient, error) {
|
||||
c, err := discover.FindServer(common.KeyDiscoverUser, sid...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rspb.NewUserClient(c), nil
|
||||
}
|
||||
|
||||
func UserNewClientLB() (rspb.UserClient, error) {
|
||||
c, err := resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameUser)
|
||||
var c *grpc.ClientConn
|
||||
var err error
|
||||
if len(sid) == 0 {
|
||||
c, err = resolver.GetGrpcClientConn("etcd:///" + common.KeyDiscoverServiceNameUser)
|
||||
} else {
|
||||
c, err = discover.FindServer(common.KeyDiscoverUser, sid...)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func findSceneBySID(sid int64, fun SceneFun) (*sceneStream, error) {
|
||||
return ss, nil
|
||||
}
|
||||
|
||||
func SendMessageToScene(sid int64, fun SceneFun, msg proto.Message, re ...bool) error {
|
||||
func sendMessageToScene(sid int64, fun SceneFun, msg proto.Message, re ...bool) error {
|
||||
ss, err := findSceneBySID(sid, fun)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -71,7 +71,7 @@ func SendMessageToScene(sid int64, fun SceneFun, msg proto.Message, re ...bool)
|
||||
}
|
||||
// 如果没有标识本次是重试的,就重试一次(默认重试)
|
||||
if re == nil || !re[0] {
|
||||
return SendMessageToScene(sid, fun, msg, true)
|
||||
return sendMessageToScene(sid, fun, msg, true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user