overflow_grpc_pool/options.go
crusader 15fe1864b3 ing
2017-08-30 15:32:53 +09:00

47 lines
802 B
Go

package overflow_grpc_pool
import (
"time"
"google.golang.org/grpc"
)
const (
// DefaultWriteTimeout is default value of Write Timeout
DefaultIdleTimeout = 0
DefaultMaxCapacity = 1
)
type (
CreateFunc func() (*grpc.ClientConn, interface{}, error)
)
// Options is configuration of the Pool of GRpc client
type Options struct {
Creators CreateFunc
IdleTimeout time.Duration
MaxIdle int
MaxCapacity int
}
// Validate validates the configuration
func (o *Options) Validate() *Options {
if o.IdleTimeout < 0 {
o.IdleTimeout = DefaultIdleTimeout
}
if o.MaxIdle < 0 {
o.MaxIdle = 0
}
if o.MaxCapacity <= 0 {
o.MaxCapacity = DefaultMaxCapacity
}
if o.Creators == nil {
o.Creators = func() (*grpc.ClientConn, interface{}, error) {
return nil, nil, nil
}
}
return o
}