|
@@ -0,0 +1,41 @@
|
|
|
+package middleground
|
|
|
+
|
|
|
+import (
|
|
|
+ "log"
|
|
|
+
|
|
|
+ "github.com/zeromicro/go-zero/core/discov"
|
|
|
+ "github.com/zeromicro/go-zero/zrpc"
|
|
|
+)
|
|
|
+
|
|
|
+type jyPoints struct {
|
|
|
+ hosts []string
|
|
|
+ key string
|
|
|
+ client zrpc.Client
|
|
|
+}
|
|
|
+
|
|
|
+func newJyPoints(hosts []string, key string) *jyPoints {
|
|
|
+ r := &jyPoints{
|
|
|
+ hosts: hosts,
|
|
|
+ key: key,
|
|
|
+ }
|
|
|
+ r.client = r.NewClient()
|
|
|
+ return r
|
|
|
+}
|
|
|
+
|
|
|
+func (r *jyPoints) NewClient() zrpc.Client {
|
|
|
+ if r.client != nil && r.client.Conn() != nil {
|
|
|
+ return r.client
|
|
|
+ }
|
|
|
+ client, err := zrpc.NewClient(zrpc.RpcClientConf{
|
|
|
+ Etcd: discov.EtcdConf{
|
|
|
+ Hosts: r.hosts,
|
|
|
+ Key: r.key,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ r.client = client
|
|
|
+ return client
|
|
|
+}
|