README ¶
net/rcp/warden
项目简介
来自 bilibili 主站技术部的 RPC 框架,融合主站技术部的核心科技,带来如飞一般的体验。
编译环境
- 请只用 Golang v1.9.x 以上版本编译执行
依赖包
Documentation ¶
Index ¶
- func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error)
- type Client
- func (c *Client) Dial(ctx context.Context, target string, opt ...grpc.DialOption) (conn *grpc.ClientConn, err error)
- func (c *Client) DialTLS(ctx context.Context, target string, file string, name string) (conn *grpc.ClientConn, err error)
- func (c *Client) SetConfig(conf *ClientConfig) (err error)
- func (c *Client) Use(handlers ...grpc.UnaryClientInterceptor) *Client
- func (c *Client) UseOpt(opt ...grpc.DialOption) *Client
- type ClientConfig
- type Server
- func (s *Server) RegisterValidation(key string, fn validator.Func) error
- func (s *Server) Run(addr string) error
- func (s *Server) RunUnix(file string) error
- func (s *Server) Serve(lis net.Listener) error
- func (s *Server) Server() *grpc.Server
- func (s *Server) SetConfig(conf *ServerConfig) (err error)
- func (s *Server) Shutdown(ctx context.Context) (err error)
- func (s *Server) Start() (*Server, error)
- func (s *Server) Use(handlers ...grpc.UnaryServerInterceptor) *Server
- type ServerConfig
Examples ¶
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
type ClientConfig ¶
type ClientConfig struct { Dial xtime.Duration Timeout xtime.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 ¶
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 ¶
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 ¶
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 ¶
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) SetConfig ¶
func (s *Server) SetConfig(conf *ServerConfig) (err error)
SetConfig hot reloads server config
func (*Server) Shutdown ¶
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.
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 xtime.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 xtime.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 xtime.Duration `dsn:"query.maxLife"` // ForceCloseWait is an additive period after MaxLifeTime after which the connection will be forcibly closed. ForceCloseWait xtime.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 xtime.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 xtime.Duration `dsn:"query.keepaliveTimeout"` }
ServerConfig is rpc server conf.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
balancer
|
|
benchmark
|
|
bench/proto
Package grpc is a generated protocol buffer package.
|
Package grpc is a generated protocol buffer package. |
encoding
|
|
examples
|
|
proto
|
|
testproto
Package testproto is a generated protocol buffer package.
|
Package testproto is a generated protocol buffer package. |