2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2021-11-16 18:15:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-11-09 08:07:49 +00:00
|
|
|
)
|
|
|
|
|
2022-01-10 09:19:46 +00:00
|
|
|
// Client is a wrapper over raw NeoFS API client.
|
|
|
|
//
|
|
|
|
// It is not allowed to override client's behaviour:
|
|
|
|
// the parameters for the all operations are write-only
|
|
|
|
// and the results of the all operations are read-only.
|
|
|
|
//
|
|
|
|
// Working client must be created via constructor New.
|
|
|
|
// Using the Client that has been created with new(Client)
|
|
|
|
// expression (or just declaring a Client variable) is unsafe
|
|
|
|
// and can lead to panic.
|
2021-12-29 13:18:09 +00:00
|
|
|
type Client struct {
|
2021-11-09 08:07:49 +00:00
|
|
|
raw *client.Client
|
|
|
|
|
|
|
|
opts *clientOptions
|
|
|
|
}
|
|
|
|
|
2022-01-10 09:19:46 +00:00
|
|
|
// New creates, initializes and returns the Client instance.
|
|
|
|
//
|
|
|
|
// If multiple options of the same config value are supplied,
|
|
|
|
// the option with the highest index in the arguments will be used.
|
2021-12-29 13:18:09 +00:00
|
|
|
func New(opts ...Option) (*Client, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
clientOptions := defaultClientOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](clientOptions)
|
|
|
|
}
|
|
|
|
|
2021-12-29 13:18:09 +00:00
|
|
|
return &Client{
|
2021-11-09 08:07:49 +00:00
|
|
|
opts: clientOptions,
|
|
|
|
raw: client.New(clientOptions.rawOpts...),
|
|
|
|
}, nil
|
|
|
|
}
|