feat: registry.

This commit is contained in:
Bobo
2025-06-02 14:09:11 +08:00
parent 0759f2d752
commit 54e887034f
37 changed files with 285 additions and 55 deletions

View File

@@ -1,16 +1,26 @@
package zookeeper
import (
zookeeperKratos "github.com/go-kratos/kratos/contrib/registry/zookeeper/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-zookeeper/zk"
conf "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
r "github.com/tx7do/kratos-bootstrap/registry"
)
func init() {
r.RegisterRegistrarCreator(string(r.ZooKeeper), func(c *conf.Registry) registry.Registrar {
return NewRegistry(c)
})
r.RegisterDiscoveryCreator(string(r.ZooKeeper), func(c *conf.Registry) registry.Discovery {
return NewRegistry(c)
})
}
// NewRegistry 创建一个注册发现客户端 - ZooKeeper
func NewRegistry(c *conf.Registry) *zookeeperKratos.Registry {
func NewRegistry(c *conf.Registry) *Registry {
if c == nil || c.Zookeeper == nil {
return nil
}
@@ -20,7 +30,7 @@ func NewRegistry(c *conf.Registry) *zookeeperKratos.Registry {
log.Fatal(err)
}
reg := zookeeperKratos.New(conn)
reg := New(conn)
if err != nil {
log.Fatal(err)
}

View File

@@ -8,15 +8,15 @@ replace (
github.com/armon/go-metrics => github.com/hashicorp/go-metrics v0.4.1
github.com/tx7do/kratos-bootstrap/api => ../../api
github.com/tx7do/kratos-bootstrap/registry => ../registry
github.com/tx7do/kratos-bootstrap/registry => ../
)
require (
github.com/go-kratos/kratos/contrib/registry/zookeeper/v2 v2.0.0-20250527152916-d6f5f00cf562
github.com/go-kratos/kratos/v2 v2.8.4
github.com/go-zookeeper/zk v1.0.4
github.com/stretchr/testify v1.10.0
github.com/tx7do/kratos-bootstrap/api v0.0.20
github.com/tx7do/kratos-bootstrap/api v0.0.21
github.com/tx7do/kratos-bootstrap/registry v0.1.0
golang.org/x/sync v0.14.0
)

View File

@@ -1,8 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kratos/kratos/contrib/registry/zookeeper/v2 v2.0.0-20250527152916-d6f5f00cf562 h1:SBDGsiqkqT6BOidznJKweIcru7eVigX8fkNWp1mZjWk=
github.com/go-kratos/kratos/contrib/registry/zookeeper/v2 v2.0.0-20250527152916-d6f5f00cf562/go.mod h1:/XjgaYgSaaoIe4YcUishDuqLpQvOSujQTk8D0cJx/Zo=
github.com/go-kratos/kratos/v2 v2.8.4 h1:eIJLE9Qq9WSoKx+Buy2uPyrahtF/lPh+Xf4MTpxhmjs=
github.com/go-kratos/kratos/v2 v2.8.4/go.mod h1:mq62W2101a5uYyRxe+7IdWubu7gZCGYqSNKwGFiiRcw=
github.com/go-zookeeper/zk v1.0.4 h1:DPzxraQx7OrPyXq2phlGlNSIyWEsAox0RJmjTseMV6I=