Documentation
¶
Index ¶
- Constants
- func WithCallTimeout(timeout time.Duration) grpc.CallOption
- type ClientMiddlewaresConf
- type ClientOption
- func WithDialOption(opt grpc.DialOption) ClientOption
- func WithNonBlock() ClientOption
- func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransportCredentials(creds credentials.TransportCredentials) ClientOption
- func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption
- type MethodTimeoutConf
- type RegisterFn
- type RpcClient
- type RpcClientConf
- type RpcServer
- type RpcServerConf
- type ServerMiddlewaresConf
Constants ¶
const ( DevMode = "dev" TestMode = "test" ProMode = "pro" )
Variables ¶
This section is empty.
Functions ¶
func WithCallTimeout ¶
func WithCallTimeout(timeout time.Duration) grpc.CallOption
WithCallTimeout return a call option with given timeout to make a method call.
Types ¶
type ClientMiddlewaresConf ¶
type ClientOption ¶
type ClientOption func(options *clientOptions)
func WithDialOption ¶
func WithDialOption(opt grpc.DialOption) ClientOption
WithDialOption returns a func to customize a clientOptions with given dial option.
func WithStreamClientInterceptor ¶
func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) ClientOption
WithStreamClientInterceptor returns a func to customize with given interceptor.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout returns a func to customize a clientOptions with given timeout.
func WithTransportCredentials ¶
func WithTransportCredentials(creds credentials.TransportCredentials) ClientOption
WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
func WithUnaryClientInterceptor ¶
func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption
WithUnaryClientInterceptor returns a func to customize with given interceptor.
type MethodTimeoutConf ¶
type MethodTimeoutConf = serverinterceptors.MethodTimeoutConf
type RegisterFn ¶
RegisterFn defines the method to register services on grpc.Server.
type RpcClient ¶
type RpcClient struct {
// contains filtered or unexported fields
}
RpcClient is a gRPC client.
func MustNewClient ¶
func MustNewClient(c RpcClientConf, options ...ClientOption) *RpcClient
MustNewClient returns a RpcClient, exits on any error.
func NewClient ¶
func NewClient(c RpcClientConf, options ...ClientOption) (*RpcClient, error)
NewClient returns a RpcClient.
func NewClientWithTarget ¶
func NewClientWithTarget(target string, opts ...ClientOption) (*RpcClient, error)
NewClientWithTarget returns a RpcClient with connecting to given target.
func (*RpcClient) Conn ¶
func (rc *RpcClient) Conn() *grpc.ClientConn
Conn returns the underlying grpc.ClientConn.
type RpcClientConf ¶
type RpcClientConf struct {
Endpoints []string
Target string `json:",optional"`
NonBlock bool `json:",default=true"`
Timeout int64 `json:",default=2000"`
KeepaliveTime time.Duration `json:",optional"`
Middlewares ClientMiddlewaresConf
}
func (RpcClientConf) BuildTarget ¶
func (cc RpcClientConf) BuildTarget() (string, error)
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
RpcServer is a gRPC server.
func MustNewServer ¶
func MustNewServer(c RpcServerConf, register RegisterFn) *RpcServer
MustNewServer returns a RpcServer, exits on any error.
func NewServer ¶
func NewServer(c RpcServerConf, register RegisterFn) (*RpcServer, error)
NewServer returns a RpcServer.
func (*RpcServer) AddOptions ¶
func (s *RpcServer) AddOptions(options ...grpc.ServerOption)
AddOptions adds given options.
func (*RpcServer) AddStreamInterceptors ¶
func (s *RpcServer) AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor)
AddStreamInterceptors adds given stream interceptors.
func (*RpcServer) AddUnaryInterceptors ¶
func (s *RpcServer) AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor)
AddUnaryInterceptors adds given unary interceptors.
type RpcServerConf ¶
type RpcServerConf struct {
Name string
ListenOn string
Mode string `json:",default=pro,options=dev|test|pro"`
Log logx.LogConf `json:",optional"`
Telemetry trace.Config `json:",optional"`
DevServer devserver.Config `json:",optional"`
Shutdown proc.ShutdownConf `json:",optional"`
Timeout int64 `json:",default=2000"`
Health bool `json:",default=true"`
Middlewares ServerMiddlewaresConf
MethodTimeouts []MethodTimeoutConf `json:",optional"`
}
func (RpcServerConf) SetUp ¶
func (sc RpcServerConf) SetUp() error
func (RpcServerConf) Validate ¶
func (sc RpcServerConf) Validate() error