refactoring
This commit is contained in:
parent
87a3b25404
commit
6474f92422
|
@ -1,8 +1,11 @@
|
||||||
package grpc_pool
|
package grpc_pool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
DefaultMaxCapacity = 1
|
||||||
|
DefaultMaxIdle = 1
|
||||||
// DefaultWriteTimeout is default value of Write Timeout
|
// DefaultWriteTimeout is default value of Write Timeout
|
||||||
DefaultIdleTimeout = 0
|
DefaultIdleTimeout = 0
|
||||||
DefaultMaxIdle = 0
|
// If Wait is true and the pool is at the MaxActive limit, then Get() waits
|
||||||
DefaultMaxCapacity = 1
|
// for a connection to be returned to the pool before returning.
|
||||||
|
DefaultWait = false
|
||||||
)
|
)
|
||||||
|
|
4
pool.go
4
pool.go
|
@ -41,12 +41,12 @@ type pool struct {
|
||||||
stopWg sync.WaitGroup
|
stopWg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ph PoolHandler) (Pool, error) {
|
func New(ph PoolHandler) Pool {
|
||||||
p := &pool{
|
p := &pool{
|
||||||
ph: ph,
|
ph: ph,
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pool) Start() error {
|
func (p *pool) Start() error {
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
type PoolHandler interface {
|
type PoolHandler interface {
|
||||||
Dial() (conn *grpc.ClientConn, client interface{}, err error)
|
Dial() (conn *grpc.ClientConn, client interface{}, err error)
|
||||||
|
|
||||||
GetIdleTimeout() time.Duration
|
|
||||||
GetMaxIdle() int
|
|
||||||
GetMaxCapacity() int
|
GetMaxCapacity() int
|
||||||
|
GetMaxIdle() int
|
||||||
|
GetIdleTimeout() time.Duration
|
||||||
Validate()
|
Validate()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,23 +9,29 @@ import (
|
||||||
|
|
||||||
// Options is configuration of the Pool of GRpc client
|
// Options is configuration of the Pool of GRpc client
|
||||||
type PoolHandlers struct {
|
type PoolHandlers struct {
|
||||||
IdleTimeout time.Duration
|
|
||||||
MaxIdle int
|
|
||||||
MaxCapacity int
|
MaxCapacity int
|
||||||
|
MaxIdle int
|
||||||
|
IdleTimeout time.Duration
|
||||||
|
// If Wait is true and the pool is at the MaxActive limit, then Get() waits
|
||||||
|
// for a connection to be returned to the pool before returning.
|
||||||
|
Wait bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *PoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
|
func (ph *PoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
|
||||||
return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented")
|
return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
|
func (ph *PoolHandlers) GetMaxCapacity() int {
|
||||||
return ph.IdleTimeout
|
return ph.MaxCapacity
|
||||||
}
|
}
|
||||||
func (ph *PoolHandlers) GetMaxIdle() int {
|
func (ph *PoolHandlers) GetMaxIdle() int {
|
||||||
return ph.MaxIdle
|
return ph.MaxIdle
|
||||||
}
|
}
|
||||||
func (ph *PoolHandlers) GetMaxCapacity() int {
|
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
|
||||||
return ph.MaxCapacity
|
return ph.IdleTimeout
|
||||||
|
}
|
||||||
|
func (ph *PoolHandlers) IsWait() bool {
|
||||||
|
return ph.Wait
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the configuration
|
// Validate validates the configuration
|
||||||
|
|
Loading…
Reference in New Issue
Block a user