Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct { Timeout time.Duration Closer io.ReadWriteCloser Decoder *gob.Decoder Encoder *gob.Encoder EncBuf *bufio.Writer }
Codec ...
func (*Codec) ReadResponseBody ¶
ReadResponseBody ...
func (*Codec) ReadResponseHeader ¶
ReadResponseHeader ...
type GRPCPool ¶
type GRPCPool struct { Mu sync.Mutex IdleTimeout time.Duration // contains filtered or unexported fields }
GRPCPool pool info
Example ¶
options := &Options{ InitTargets: []string{"127.0.0.1:8080"}, InitCap: 5, MaxCap: 30, timeoutType: IdleTimeoutType, DialTimeout: time.Second * 5, IdleTimeout: time.Second * 60, ReadTimeout: time.Second * 5, WriteTimeout: time.Second * 5, } p, err := NewGRPCPool(options, grpc.WithInsecure()) if err != nil { log.Printf("%#v\n", err) return } if p == nil { log.Printf("p= %#v\n", p) return } defer p.Close() //todo //danamic update targets //options.Input()<-&[]string{} conn, err := p.Get() if err != nil { log.Printf("%#v\n", err) return } defer p.Put(conn) //todo //Conn.DoSomething() log.Printf("len=%d\n", p.IdleCount())
Output:
func NewGRPCPool ¶
func NewGRPCPool(o *Options, dialOptions ...grpc.DialOption) (*GRPCPool, error)
NewGRPCPool init grpc pool
type GrpcIdleConn ¶
type GrpcIdleConn struct { Conn *grpc.ClientConn // contains filtered or unexported fields }
type Options ¶
type Options struct { InitTargets []string //InitTargets init targets InitCap int // init connection MaxCap int // max connections TimeoutType TimeoutType //timeout type, fixed or idle DialTimeout time.Duration //dial timeout IdleTimeout time.Duration //timeout in program ReadTimeout time.Duration //unused WriteTimeout time.Duration //unused // contains filtered or unexported fields }
Options pool options
func NewOptions ¶
func NewOptions() *Options
NewOptions returns a new newOptions instance with sane defaults.
type RPCPool ¶
type RPCPool struct { Mu sync.Mutex IdleTimeout time.Duration // contains filtered or unexported fields }
RPCPool pool info
Example ¶
options := &Options{ InitTargets: []string{"127.0.0.1:8080"}, InitCap: 5, MaxCap: 30, DialTimeout: time.Second * 5, IdleTimeout: time.Second * 60, ReadTimeout: time.Second * 5, WriteTimeout: time.Second * 5, } p, err := NewRPCPool(options) if err != nil { log.Printf("%#v\n", err) return } if p == nil { log.Printf("p= %#v\n", p) return } defer p.Close() //todo //danamic update targets //options.Input()<-&[]string{} conn, err := p.Get() if err != nil { log.Printf("%#v\n", err) return } defer p.Put(conn) //todo //Conn.DoSomething() log.Printf("len=%d\n", p.IdleCount())
Output:
type TCPPool ¶
type TCPPool struct { Mu sync.Mutex IdleTimeout time.Duration // contains filtered or unexported fields }
TCPPool pool info
Example ¶
options := &Options{ InitTargets: []string{"127.0.0.1:8080"}, InitCap: 5, MaxCap: 30, DialTimeout: time.Second * 5, IdleTimeout: time.Second * 60, ReadTimeout: time.Second * 5, WriteTimeout: time.Second * 5, } p, err := NewTCPPool(options) if err != nil { log.Printf("%#v\n", err) return } if p == nil { log.Printf("p= %#v\n", p) return } defer p.Close() //todo //danamic update targets //options.Input()<-&[]string{} conn, err := p.Get() if err != nil { log.Printf("%#v\n", err) return } defer p.Put(conn) //todo //Conn.DoSomething() log.Printf("len=%d\n", p.IdleCount())
Output:
type TimeoutType ¶
type TimeoutType int
const ( IdleTimeoutType TimeoutType = iota + 1 //idled during timeout FixedTimeoutType //alive during timeout, like life cycle )
Click to show internal directories.
Click to hide internal directories.