grpcwrapper

package module
v0.0.0-...-0c2590b Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 16 Imported by: 0

README

GrpcWrapper

基于grpc进行封装,支持服务发现,服务注册,负载均衡,服务治理等功能。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PClient

type PClient struct {
	// contains filtered or unexported fields
}

func NewPClient

func NewPClient(serviceName string, interceptors ...grpc.UnaryClientInterceptor) (*PClient, error)

func (*PClient) Conn

func (p *PClient) Conn() *grpc.ClientConn

type PServer

type PServer struct {
	// contains filtered or unexported fields
}

func NewPServer

func NewPServer(opts ...ServerOption) *PServer

func (*PServer) RegisterService

func (p *PServer) RegisterService(register ...RegisterFn)

eg :

p.RegisterService(func(server *grpc.Server) {
    test.RegisterGreeterServer(server, &Server{})
})

func (*PServer) RegisterUnaryServerInterceptor

func (p *PServer) RegisterUnaryServerInterceptor(i grpc.UnaryServerInterceptor)

注册自定义拦截器,例如限流拦截器或者自己的一些业务自定义拦截器

func (*PServer) Start

func (p *PServer) Start(ctx context.Context)

开启server

type RegisterFn

type RegisterFn func(*grpc.Server)

type ServerOption

type ServerOption func(opts *serverOptions)

func WithHealth

func WithHealth(health bool) ServerOption

set health

func WithIP

func WithIP(ip string) ServerOption

set ip

func WithPort

func WithPort(port int) ServerOption

set port

func WithServiceName

func WithServiceName(serviceName string) ServerOption

set serviceName

func WithWeight

func WithWeight(weight int) ServerOption

set weight

Directories

Path Synopsis
example
interceptor

Jump to

Keyboard shortcuts

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