update grpcx
This commit is contained in:
parent
7827731423
commit
6648f2d530
@ -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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
45
with/grpcx.go
Normal file
45
with/grpcx.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user