warden

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error)

NewConn will create a grpc conn by default config.

Types

type Client

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

Client is the framework's client side instance, it contains the ctx, opt and interceptors. Create an instance of Client, by using NewClient().

func DefaultClient

func DefaultClient() *Client

DefaultClient returns a new default Client instance with a default client interceptor and default dialoption. opt can be used to add grpc dial options.

func NewClient

func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client

NewClient returns a new blank Client instance with a default client interceptor. opt can be used to add grpc dial options.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, target string, opt ...grpc.DialOption) (conn *grpc.ClientConn, err error)

Dial creates a client connection to the given target. Target format is scheme://authority/endpoint?query_arg=value example: discovery://default/account.account.service?cluster=shfy01&cluster=shfy02

func (*Client) DialTLS

func (c *Client) DialTLS(ctx context.Context, target string, file string, name string) (conn *grpc.ClientConn, err error)

DialTLS creates a client connection over tls transport to the given target.

func (*Client) SetConfig

func (c *Client) SetConfig(conf *ClientConfig) (err error)

SetConfig hot reloads client config

func (*Client) Use

func (c *Client) Use(handlers ...grpc.UnaryClientInterceptor) *Client

Use attachs a global inteceptor to the Client. For example, this is the right place for a circuit breaker or error management inteceptor.

func (*Client) UseOpt

func (c *Client) UseOpt(opt ...grpc.DialOption) *Client

UseOpt attachs a global grpc DialOption to the Client.

type ClientConfig

type ClientConfig struct {
	Dial     ctime.Duration
	Timeout  ctime.Duration
	Breaker  *breaker.Config
	Method   map[string]*ClientConfig
	Clusters []string
	Zone     string
	Subset   int
	NonBlock bool
}

ClientConfig is rpc client conf.

type Server

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

Server is the framework's server side instance, it contains the GrpcServer, interceptor and interceptors. Create an instance of Server, by using NewServer().

func NewServer

func NewServer(conf *ServerConfig, opt ...grpc.ServerOption) (s *Server)

NewServer returns a new blank Server instance with a default server interceptor.

func (*Server) RegisterValidation

func (s *Server) RegisterValidation(key string, fn validator.Func) error

RegisterValidation adds a validation Func to a Validate's map of validators denoted by the key NOTE: if the key already exists, the previous validation function will be replaced. NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation

func (*Server) Run

func (s *Server) Run(addr string) error

Run create a tcp listener and start goroutine for serving each incoming request. Run will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) RunUnix

func (s *Server) RunUnix(file string) error

RunUnix create a unix listener and start goroutine for serving each incoming request. RunUnix will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) Serve

func (s *Server) Serve(lis net.Listener) error

Serve accepts incoming connections on the listener lis, creating a new ServerTransport and service goroutine for each. Serve will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) Server

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

Server return the grpc server for registering service.

func (*Server) SetConfig

func (s *Server) SetConfig(conf *ServerConfig) (err error)

SetConfig hot reloads server config

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) (err error)

Shutdown stops the server gracefully. It stops the server from accepting new connections and RPCs and blocks until all the pending RPCs are finished or the context deadline is reached.

func (*Server) Start

func (s *Server) Start() (*Server, error)

Start create a new goroutine run server with configured listen addr will panic if any error happend return server itself

func (*Server) Use

func (s *Server) Use(handlers ...grpc.UnaryServerInterceptor) *Server

Use attachs a global inteceptor to the server. For example, this is the right place for a rate limiter or error management inteceptor.

type ServerConfig

type ServerConfig struct {
	// Network is grpc listen network,default value is tcp
	Network string `dsn:"network"`
	// Addr is grpc listen addr,default value is 0.0.0.0:9000
	Addr string `dsn:"address"`
	// Timeout is context timeout for per rpc call.
	Timeout ctime.Duration `dsn:"query.timeout"`
	// IdleTimeout is a duration for the amount of time after which an idle connection would be closed by sending a GoAway.
	// Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment.
	IdleTimeout ctime.Duration `dsn:"query.idleTimeout"`
	// MaxLifeTime is a duration for the maximum amount of time a connection may exist before it will be closed by sending a GoAway.
	// A random jitter of +/-10% will be added to MaxConnectionAge to spread out connection storms.
	MaxLifeTime ctime.Duration `dsn:"query.maxLife"`
	// ForceCloseWait is an additive period after MaxLifeTime after which the connection will be forcibly closed.
	ForceCloseWait ctime.Duration `dsn:"query.closeWait"`
	// KeepAliveInterval is after a duration of this time if the server doesn't see any activity it pings the client to see if the transport is still alive.
	KeepAliveInterval ctime.Duration `dsn:"query.keepaliveInterval"`
	// KeepAliveTimeout  is After having pinged for keepalive check, the server waits for a duration of Timeout and if no activity is seen even after that
	// the connection is closed.
	KeepAliveTimeout ctime.Duration `dsn:"query.keepaliveTimeout"`
}

ServerConfig is rpc server conf.

Directories

Path Synopsis
balancer
wrr
benchmark
bench/proto
Package grpc is a generated protocol buffer package.
Package grpc is a generated protocol buffer package.
encoding

Jump to

Keyboard shortcuts

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