refactoring

This commit is contained in:
crusader 2017-11-09 16:43:43 +09:00
parent 87a3b25404
commit 6474f92422
4 changed files with 21 additions and 12 deletions

View File

@ -1,8 +1,11 @@
package grpc_pool
const (
DefaultMaxCapacity = 1
DefaultMaxIdle = 1
// DefaultWriteTimeout is default value of Write Timeout
DefaultIdleTimeout = 0
DefaultMaxIdle = 0
DefaultMaxCapacity = 1
// 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.
DefaultWait = false
)

View File

@ -41,12 +41,12 @@ type pool struct {
stopWg sync.WaitGroup
}
func New(ph PoolHandler) (Pool, error) {
func New(ph PoolHandler) Pool {
p := &pool{
ph: ph,
}
return p, nil
return p
}
func (p *pool) Start() error {

View File

@ -9,8 +9,8 @@ import (
type PoolHandler interface {
Dial() (conn *grpc.ClientConn, client interface{}, err error)
GetIdleTimeout() time.Duration
GetMaxIdle() int
GetMaxCapacity() int
GetMaxIdle() int
GetIdleTimeout() time.Duration
Validate()
}

View File

@ -9,23 +9,29 @@ import (
// Options is configuration of the Pool of GRpc client
type PoolHandlers struct {
IdleTimeout time.Duration
MaxIdle 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) {
return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented")
}
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
return ph.IdleTimeout
func (ph *PoolHandlers) GetMaxCapacity() int {
return ph.MaxCapacity
}
func (ph *PoolHandlers) GetMaxIdle() int {
return ph.MaxIdle
}
func (ph *PoolHandlers) GetMaxCapacity() int {
return ph.MaxCapacity
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
return ph.IdleTimeout
}
func (ph *PoolHandlers) IsWait() bool {
return ph.Wait
}
// Validate validates the configuration