fix package
This commit is contained in:
parent
5a310fa8c6
commit
b67fa1d599
@ -1,26 +1,56 @@
|
||||
package config
|
||||
package grpcx
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.linkiio.cn/linkpay/invoke/chain"
|
||||
"github.com/gogf/gf/contrib/registry/etcd/v2"
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var Endpoint = os.Getenv("ETCD_ENDPOINTS")
|
||||
|
||||
var GrpcConfig *grpcx.GrpcServerConfig = grpcx.Server.NewConfig()
|
||||
|
||||
func Etcd() *etcd.Registry {
|
||||
return etcd.New(Endpoint)
|
||||
}
|
||||
|
||||
func Registry(f ...func()) {
|
||||
func SetOptions(o ...grpc.ServerOption) *grpcx.GrpcServerConfig {
|
||||
|
||||
GrpcConfig.Options = append(GrpcConfig.Options, o...)
|
||||
return GrpcConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务注册
|
||||
* @param void
|
||||
* @author dc.To
|
||||
* @version 20250427
|
||||
*/
|
||||
func Registry(f ...func(*grpcx.GrpcServer)) {
|
||||
GrpcConfig.Options = append(GrpcConfig.Options, []grpc.ServerOption{
|
||||
grpcx.Server.ChainUnary(
|
||||
grpcx.Server.UnaryValidate,
|
||||
chain.ClientContextUnaryChain,
|
||||
chain.ClientMetadataUnaryChain,
|
||||
)}...,
|
||||
)
|
||||
if Endpoint != "" {
|
||||
grpcx.Resolver.Register(Etcd())
|
||||
}
|
||||
|
||||
s := grpcx.Server.New(GrpcConfig)
|
||||
|
||||
for _, fn := range f {
|
||||
fn()
|
||||
fn(s)
|
||||
}
|
||||
|
||||
Reflect(s.Server)
|
||||
|
||||
s.Run()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user