diff --git a/registry/etcd.go b/registry/etcd.go deleted file mode 100644 index a2e40c5..0000000 --- a/registry/etcd.go +++ /dev/null @@ -1,18 +0,0 @@ -package config - -import ( - "os" - - "github.com/gogf/gf/contrib/registry/etcd/v2" - "github.com/gogf/gf/contrib/rpc/grpcx/v2" -) - -func Endpoint() string { - return os.Getenv("ETCD_ENDPOINTS") -} - -func Etcd() { - if Endpoint() != "" { - grpcx.Resolver.Register(etcd.New(Endpoint())) - } -} diff --git a/with/grpcx.go b/with/grpcx.go new file mode 100644 index 0000000..e854136 --- /dev/null +++ b/with/grpcx.go @@ -0,0 +1,45 @@ +package config + +import ( + "os" + + "github.com/gogf/gf/contrib/registry/etcd/v2" + "github.com/gogf/gf/contrib/rpc/grpcx/v2" + "google.golang.org/grpc/reflection" +) + +var Endpoint = os.Getenv("ETCD_ENDPOINTS") + +func Etcd() *etcd.Registry { + return etcd.New(Endpoint) +} + +func Registry(f ...func()) { + if Endpoint != "" { + grpcx.Resolver.Register(Etcd()) + } + for _, fn := range f { + fn() + } +} + +/** + * grpc reflect + * @author dc.To + * @version 20250427 + */ +func Reflect(s reflection.GRPCServer, f ...func()) { + if Endpoint == "" { + reflection.Register(s) + } + for _, fn := range f { + fn() + } +} + +func Resolve[T any](value T, f func(T) T) T { + if f == nil { + return value + } + return f(value) +}