89be8d3f5a
Add `Conn` method to `Client` interface which must return the underlying connection. Implement new method on the core structure. `Conn` can be used to control the connection (e.g. for closing). Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
47 lines
737 B
Go
47 lines
737 B
Go
package client
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/client"
|
|
)
|
|
|
|
// Client represents NeoFS client.
|
|
type Client interface {
|
|
Accounting
|
|
Container
|
|
Netmap
|
|
Object
|
|
Session
|
|
Reputation
|
|
|
|
// Raw must return underlying raw protobuf client.
|
|
Raw() *client.Client
|
|
|
|
// Conn must return underlying connection.
|
|
//
|
|
// Must return a non-nil result after the first RPC call
|
|
// completed without a connection error.
|
|
Conn() io.Closer
|
|
}
|
|
|
|
type clientImpl struct {
|
|
onceInit sync.Once
|
|
|
|
raw *client.Client
|
|
|
|
opts *clientOptions
|
|
}
|
|
|
|
func New(opts ...Option) (Client, error) {
|
|
clientOptions := defaultClientOptions()
|
|
|
|
for i := range opts {
|
|
opts[i](clientOptions)
|
|
}
|
|
|
|
return &clientImpl{
|
|
opts: clientOptions,
|
|
}, nil
|
|
}
|