grpcservice

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	S_ServiceName = "/zservice/services/%s"
)

Variables

This section is empty.

Functions

func ClientUnaryInterceptor

func ClientUnaryInterceptor(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

unaryInterceptor 一个简单的 unary interceptor 示例。

func NewGrpcClient

func NewGrpcClient(opt *GrpcClientOption) (*grpc.ClientConn, error)

GRPC 客户端创建,优先使用 Addr 配置的地址直连,如果 Addr 未配置,使用 ETCD 服务发现

func ServerStreamInterceptor

func ServerStreamInterceptor(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

ServerStreamInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs.

func ServerUnaryInterceptor

func ServerUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

Types

type GrpcClientOption

type GrpcClientOption struct {
	ServiceName string           // 服务名
	EtcdClient  *clientv3.Client // etcd 客户端
	Addr        string           // grcp 服务器地址
}

type GrpcService

type GrpcService struct {
	*zservice.ZService
	GrpcServer *grpc.Server
}

func NewGrpcService

func NewGrpcService(c *GrpcServiceConfig) *GrpcService

type GrpcServiceConfig

type GrpcServiceConfig struct {
	ListenPort string // 监听端口
	EtcdClient *clientv3.Client
	OnStart    func(*GrpcService) // 启动的回调
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL