2021-03-12 11:17:16 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2021-12-24 10:16:55 +00:00
|
|
|
"time"
|
|
|
|
|
2021-03-12 11:17:16 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2021-12-24 10:16:55 +00:00
|
|
|
const defaultRWTimeout = 1 * time.Minute
|
|
|
|
|
2021-03-12 11:17:16 +00:00
|
|
|
type cfg struct {
|
2021-12-24 10:16:55 +00:00
|
|
|
con *grpc.ClientConn
|
|
|
|
rwTimeout time.Duration
|
2021-03-12 11:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
2021-12-24 10:16:55 +00:00
|
|
|
return &cfg{
|
|
|
|
rwTimeout: defaultRWTimeout,
|
|
|
|
}
|
2021-03-12 11:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithClientConnection returns option to set gRPC connection
|
|
|
|
// to the remote server.
|
|
|
|
func WithClientConnection(con *grpc.ClientConn) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.con = con
|
|
|
|
}
|
|
|
|
}
|
2021-12-24 10:16:55 +00:00
|
|
|
|
|
|
|
// WithRWTimeout returns option to specify rwTimeout
|
|
|
|
// for reading and writing single gRPC message.
|
|
|
|
func WithRWTimeout(t time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.rwTimeout = t
|
|
|
|
}
|
|
|
|
}
|