grpcx

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: Apache-2.0 Imports: 21 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDialOption added in v0.2.0

func RegisterDialOption(name string, f func(configuration *conf.Configuration) grpc.DialOption)

RegisterDialOption register grpc dial option on client side

func RegisterGrpcServerOption

func RegisterGrpcServerOption(name string, handler ServerOptionFunc)

RegisterGrpcServerOption register grpc server option

func RegisterGrpcStreamInterceptor added in v0.0.3

func RegisterGrpcStreamInterceptor(name string, handler StreamServerInterceptorFunc)

RegisterGrpcStreamInterceptor register grpc stream interceptor

func RegisterGrpcUnaryInterceptor

func RegisterGrpcUnaryInterceptor(name string, handler UnaryServerInterceptorFunc)

RegisterGrpcUnaryInterceptor register grpc unary interceptor

func RegisterStreamClientInterceptor added in v0.2.0

func RegisterStreamClientInterceptor(name string, f func(configuration *conf.Configuration) grpc.StreamClientInterceptor)

RegisterStreamClientInterceptor register grpc stream client interceptor

func RegisterUnaryClientInterceptor added in v0.2.0

func RegisterUnaryClientInterceptor(name string, f func(configuration *conf.Configuration) grpc.UnaryClientInterceptor)

RegisterUnaryClientInterceptor register grpc unary client interceptor

Types

type Client added in v0.2.0

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

Client is a grpc client helper,build a grpc client connection by configuration with registry. the configuration is like this:

server:  for grpc server info
registry:  for registry center info
client:  for grpc client info
  target:  for grpc service info using with registry or dial directly

func NewClient added in v0.2.0

func NewClient(cfg *conf.Configuration) (*Client, error)

func (*Client) Apply added in v0.2.0

func (c *Client) Apply(cfg *conf.Configuration) error

func (*Client) Dial added in v0.2.0

func (c *Client) Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a gRPC client connection with the given target, and covert to DialContext if client.timeout > 0

func (*Client) DialContext added in v0.2.0

func (c *Client) DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext creates a gRPC client connection with the given target.

The target will be parsed as a URL.your resolver must parse the target.

type DialOptionFunc added in v0.2.0

type DialOptionFunc func(*conf.Configuration) grpc.DialOption

client side

type Option

type Option func(s *serverOptions)

func WithConfiguration added in v0.0.3

func WithConfiguration(cfg *conf.Configuration) Option

func WithGracefulStop added in v0.1.0

func WithGracefulStop() Option

WithGracefulStop indicate use graceful stop

func WithGrpcLogger added in v0.2.0

func WithGrpcLogger() Option

WithGrpcLogger set grpclog.LoggerV2 with the component logger named "grpc". if you need to see grpc log, you should call this option.

notice: call this while go test may cause race condition.

func WithGrpcOption

func WithGrpcOption(opts ...grpc.ServerOption) Option

func WithListener added in v0.5.1

func WithListener(lis net.Listener) Option

WithListener indicate use listener. if set listener, it will ignore the address setting.

type Server

type Server struct {

	// ServiceInfos is for service discovery, it converts from grpc service info
	ServiceInfos []*registry.ServiceInfo
	// contains filtered or unexported fields
}

Server is extended the native grpc server

func New

func New(opts ...Option) *Server

New creates a new grpc server.

func (*Server) Apply

func (s *Server) Apply(cfg *conf.Configuration) error

Apply the configuration to the server.

func (*Server) Engine

func (s *Server) Engine() *grpc.Server

func (*Server) ListenAndServe added in v0.0.3

func (s *Server) ListenAndServe() (err error)

ListenAndServe call net listen to start grpc server and registry service

func (*Server) Run

func (s *Server) Run() error

Run is a sample way to start the grpc server with gracefulStop stop

func (*Server) Start added in v0.1.0

func (s *Server) Start(_ context.Context) error

func (*Server) Stop

func (s *Server) Stop(_ context.Context) (err error)

type ServerConfig

type ServerConfig struct {
	Addr      string `json:"addr" yaml:"addr"`
	Namespace string `json:"namespace" yaml:"namespace"`
	Version   string `json:"version" yaml:"version"`
}

type ServerOptionFunc added in v0.2.0

type ServerOptionFunc func(*conf.Configuration) grpc.ServerOption

server side

type StreamClientInterceptorFunc added in v0.2.0

type StreamClientInterceptorFunc func(*conf.Configuration) grpc.StreamClientInterceptor

type StreamServerInterceptorFunc added in v0.2.0

type StreamServerInterceptorFunc func(*conf.Configuration) grpc.StreamServerInterceptor

type UnaryClientInterceptorFunc added in v0.2.0

type UnaryClientInterceptorFunc func(*conf.Configuration) grpc.UnaryClientInterceptor

type UnaryServerInterceptorFunc added in v0.2.0

type UnaryServerInterceptorFunc func(*conf.Configuration) grpc.UnaryServerInterceptor

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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