forked from TrueCloudLab/frostfs-sdk-go
[#189] client: Make PrmDial fields public
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
e91d40e250
commit
3787477133
4 changed files with 51 additions and 45 deletions
|
@ -78,31 +78,22 @@ func (c *Client) Init(prm PrmInit) {
|
|||
//
|
||||
// See also Init / Close.
|
||||
func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
||||
if prm.endpoint == "" {
|
||||
if prm.Endpoint == "" {
|
||||
return errorServerAddrUnset
|
||||
}
|
||||
|
||||
if prm.timeoutDialSet {
|
||||
if prm.timeoutDial <= 0 {
|
||||
return errorNonPositiveTimeout
|
||||
}
|
||||
} else {
|
||||
prm.timeoutDial = 5 * time.Second
|
||||
if prm.DialTimeout <= 0 {
|
||||
prm.DialTimeout = defaultDialTimeout
|
||||
}
|
||||
|
||||
if prm.streamTimeoutSet {
|
||||
if prm.streamTimeout <= 0 {
|
||||
return errorNonPositiveTimeout
|
||||
}
|
||||
} else {
|
||||
prm.streamTimeout = 10 * time.Second
|
||||
if prm.StreamTimeout <= 0 {
|
||||
prm.StreamTimeout = defaultStreamTimeout
|
||||
}
|
||||
|
||||
c.c = *client.New(append(
|
||||
client.WithNetworkURIAddress(prm.endpoint, prm.tlsConfig),
|
||||
client.WithDialTimeout(prm.timeoutDial),
|
||||
client.WithRWTimeout(prm.streamTimeout),
|
||||
client.WithGRPCDialOptions(prm.dialOptions),
|
||||
client.WithNetworkURIAddress(prm.Endpoint, prm.TLSConfig),
|
||||
client.WithDialTimeout(prm.DialTimeout),
|
||||
client.WithRWTimeout(prm.StreamTimeout),
|
||||
client.WithGRPCDialOptions(prm.GRPCDialOptions),
|
||||
)...)
|
||||
|
||||
c.setFrostFSAPIServer((*coreServer)(&c.c))
|
||||
|
@ -185,21 +176,26 @@ func (x *PrmInit) SetResponseInfoCallback(f func(ResponseMetaInfo) error) {
|
|||
x.ResponseInfoCallback = f
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
defaultStreamTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
// PrmDial groups connection parameters for the Client.
|
||||
//
|
||||
// See also Dial.
|
||||
type PrmDial struct {
|
||||
endpoint string
|
||||
Endpoint string
|
||||
|
||||
tlsConfig *tls.Config
|
||||
TLSConfig *tls.Config
|
||||
|
||||
timeoutDialSet bool
|
||||
timeoutDial time.Duration
|
||||
// If DialTimeout is non-positive, then it's set to defaultDialTimeout.
|
||||
DialTimeout time.Duration
|
||||
|
||||
streamTimeoutSet bool
|
||||
streamTimeout time.Duration
|
||||
// If StreamTimeout is non-positive, then it's set to defaultStreamTimeout.
|
||||
StreamTimeout time.Duration
|
||||
|
||||
dialOptions []grpc.DialOption
|
||||
GRPCDialOptions []grpc.DialOption
|
||||
}
|
||||
|
||||
// SetServerURI sets server URI in the FrostFS network.
|
||||
|
@ -215,33 +211,41 @@ type PrmDial struct {
|
|||
// grpcs
|
||||
//
|
||||
// See also SetTLSConfig.
|
||||
//
|
||||
// Deprecated: Use PrmDial.Endpoint instead.
|
||||
func (x *PrmDial) SetServerURI(endpoint string) {
|
||||
x.endpoint = endpoint
|
||||
x.Endpoint = endpoint
|
||||
}
|
||||
|
||||
// SetTLSConfig sets tls.Config to open TLS client connection
|
||||
// to the FrostFS server. Nil (default) means insecure connection.
|
||||
//
|
||||
// See also SetServerURI.
|
||||
//
|
||||
// Depreacted: Use PrmDial.TLSConfig instead.
|
||||
func (x *PrmDial) SetTLSConfig(tlsConfig *tls.Config) {
|
||||
x.tlsConfig = tlsConfig
|
||||
x.TLSConfig = tlsConfig
|
||||
}
|
||||
|
||||
// SetTimeout sets the timeout for connection to be established.
|
||||
// MUST BE positive. If not called, 5s timeout will be used by default.
|
||||
//
|
||||
// Deprecated: Use PrmDial.DialTimeout instead.
|
||||
func (x *PrmDial) SetTimeout(timeout time.Duration) {
|
||||
x.timeoutDialSet = true
|
||||
x.timeoutDial = timeout
|
||||
x.DialTimeout = timeout
|
||||
}
|
||||
|
||||
// SetStreamTimeout sets the timeout for individual operations in streaming RPC.
|
||||
// MUST BE positive. If not called, 10s timeout will be used by default.
|
||||
//
|
||||
// Deprecated: Use PrmDial.StreamTimeout instead.
|
||||
func (x *PrmDial) SetStreamTimeout(timeout time.Duration) {
|
||||
x.streamTimeoutSet = true
|
||||
x.streamTimeout = timeout
|
||||
x.StreamTimeout = timeout
|
||||
}
|
||||
|
||||
// SetGRPCDialOptions sets the gRPC dial options for new gRPC client connection.
|
||||
//
|
||||
// Deprecated: Use PrmDial.GRPCDialOptions instead.
|
||||
func (x *PrmDial) SetGRPCDialOptions(opts ...grpc.DialOption) {
|
||||
x.dialOptions = opts
|
||||
x.GRPCDialOptions = opts
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue