47 lines
802 B
Go
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
|
|
}
|