ngrpc

package module
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

ngrpc

grpc server/client 包装一些grpc功能。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocalIPv4 added in v2.2.0

func LocalIPv4(name ...string) (ipAddr string, err error)

LocalIPv4 本地IP

func StreamServerInterceptor

func StreamServerInterceptor(f GrpcContextHandler) grpc.StreamServerInterceptor

StreamServerInterceptor ...

func UnaryServerInterceptor

func UnaryServerInterceptor(f GrpcContextHandler) grpc.UnaryServerInterceptor

UnaryServerInterceptor ...

Types

type ClientOption added in v2.2.0

type ClientOption func(*ClientOptions)

ClientOption 为可选参数赋值的函数

func WithClientAddress added in v2.2.0

func WithClientAddress(address string) ClientOption

func WithClientDiscovery added in v2.2.0

func WithClientDiscovery(discovery resolver.Discovery) ClientOption

func WithClientLogger added in v2.2.0

func WithClientLogger(log Logger) ClientOption

func WithClientName added in v2.2.0

func WithClientName(name string) ClientOption

func WithClientStreamClientInterceptors added in v2.2.0

func WithClientStreamClientInterceptors(streamClientInterceptors ...grpc.StreamClientInterceptor) ClientOption

func WithClientUnaryClientInterceptors added in v2.2.0

func WithClientUnaryClientInterceptors(unaryClientInterceptors ...grpc.UnaryClientInterceptor) ClientOption

type ClientOptions added in v2.2.0

type ClientOptions struct {
	Name                     string
	Address                  string
	Log                      Logger
	StreamClientInterceptors []grpc.StreamClientInterceptor
	UnaryClientInterceptors  []grpc.UnaryClientInterceptor
	// contains filtered or unexported fields
}

ClientOptions 可选参数列表

func NewClientOptions added in v2.2.0

func NewClientOptions(opts ...ClientOption) ClientOptions

NewClientOptions 创建可选参数

type GrpcClient

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

GrpcClient grpc客户端

func NewGrpcClient

func NewGrpcClient(ctx context.Context, opts ...ClientOption) *GrpcClient

NewGrpcClient 创建Grpc客户端

func (*GrpcClient) Close

func (c *GrpcClient) Close(ctx context.Context)

Close 关闭

func (*GrpcClient) GetConn

func (c *GrpcClient) GetConn() *grpc.ClientConn

GetConn 获取客户端连接

type GrpcContextHandler

type GrpcContextHandler func(ctx context.Context) context.Context

GrpcContextHandler ...

type GrpcServer

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

GrpcServer 服务端

func NewGrpcServer

func NewGrpcServer(ctx context.Context, opts ...ServerOption) *GrpcServer

NewGrpcServer 创建Grpc服务端

func (*GrpcServer) GetSrv

func (s *GrpcServer) GetSrv() *grpc.Server

GetSrv 获取rpc server

func (*GrpcServer) Run

func (s *GrpcServer) Run()

func (*GrpcServer) Start

func (s *GrpcServer) Start()

func (*GrpcServer) Stop

func (s *GrpcServer) Stop()

type Logger added in v2.2.0

type Logger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Debugln(ctx context.Context, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Infoln(ctx context.Context, args ...interface{})
	Warnf(ctx context.Context, format string, args ...interface{})
	Warnln(ctx context.Context, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
	Errorln(ctx context.Context, args ...interface{})
	Fatalf(ctx context.Context, format string, args ...interface{})
	Fatalln(ctx context.Context, args ...interface{})
}

Logger logger

type ServerOption added in v2.2.0

type ServerOption func(*ServerOptions)

ServerOption 为可选参数赋值的函数

func WithServerAddress added in v2.2.0

func WithServerAddress(address string) ServerOption

func WithServerLogger added in v2.2.0

func WithServerLogger(log Logger) ServerOption

func WithServerName added in v2.2.0

func WithServerName(name string) ServerOption

func WithServerRandomPort added in v2.2.0

func WithServerRandomPort(randomPort bool) ServerOption

func WithServerRegister added in v2.2.0

func WithServerRegister(register resolver.Registry) ServerOption

func WithServerStreamServerInterceptors added in v2.2.0

func WithServerStreamServerInterceptors(streamServerInterceptors ...grpc.StreamServerInterceptor) ServerOption

func WithServerUnaryServerInterceptors added in v2.2.0

func WithServerUnaryServerInterceptors(unaryServerInterceptors ...grpc.UnaryServerInterceptor) ServerOption

type ServerOptions added in v2.2.0

type ServerOptions struct {
	Name                     string
	Address                  string
	Log                      Logger
	StreamServerInterceptors []grpc.StreamServerInterceptor
	UnaryServerInterceptors  []grpc.UnaryServerInterceptor

	RandomPort bool
	// contains filtered or unexported fields
}

ServerOptions 可选参数列表

func NewServerOptions added in v2.2.0

func NewServerOptions(opts ...ServerOption) ServerOptions

NewServerOptions 创建可选参数

type StdLogger added in v2.2.0

type StdLogger struct {
}

func (StdLogger) Debugf added in v2.2.0

func (StdLogger) Debugf(ctx context.Context, format string, args ...interface{})

func (StdLogger) Debugln added in v2.2.0

func (StdLogger) Debugln(ctx context.Context, args ...interface{})

func (StdLogger) Errorf added in v2.2.0

func (StdLogger) Errorf(ctx context.Context, format string, args ...interface{})

func (StdLogger) Errorln added in v2.2.0

func (StdLogger) Errorln(ctx context.Context, args ...interface{})

func (StdLogger) Fatalf added in v2.2.0

func (StdLogger) Fatalf(ctx context.Context, format string, args ...interface{})

func (StdLogger) Fatalln added in v2.2.0

func (StdLogger) Fatalln(ctx context.Context, args ...interface{})

func (StdLogger) Infof added in v2.2.0

func (StdLogger) Infof(ctx context.Context, format string, args ...interface{})

func (StdLogger) Infoln added in v2.2.0

func (StdLogger) Infoln(ctx context.Context, args ...interface{})

func (StdLogger) Warnf added in v2.2.0

func (StdLogger) Warnf(ctx context.Context, format string, args ...interface{})

func (StdLogger) Warnln added in v2.2.0

func (StdLogger) Warnln(ctx context.Context, args ...interface{})

Directories

Path Synopsis
health

Jump to

Keyboard shortcuts

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