WH01243 2 سال پیش
والد
کامیت
8b5fc86f3d
2فایلهای تغییر یافته به همراه45 افزوده شده و 0 حذف شده
  1. 1 0
      middleground/middleground.go
  2. 44 0
      middleground/publicservice.go

+ 1 - 0
middleground/middleground.go

@@ -7,6 +7,7 @@ type Middleground struct {
 	PowerCheckCenter     *powerCheckCenter
 	EntManageApplication *entManageApplication
 	ActivityCenter       *activity
+	Publicservice        *publicservice
 }
 
 func NewMiddleground(hosts []string) *Middleground {

+ 44 - 0
middleground/publicservice.go

@@ -0,0 +1,44 @@
+package middleground
+
+import (
+	"context"
+	"log"
+
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type publicservice struct {
+	hosts  []string
+	key    string
+	client zrpc.Client
+}
+
+func newPublicservice(hosts []string, key string) *publicservice {
+	r := &userCenter{
+		hosts: hosts,
+		key:   key,
+	}
+	r.client = r.NewClient()
+	return r
+}
+
+func (u *publicservice) NewClient() zrpc.Client {
+	if u.client != nil && u.client.Conn() != nil {
+		return u.client
+	}
+	client, err := zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: u.hosts,
+			Key:   u.key,
+		},
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	u.client = client
+	return client
+}