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.
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Each method which produces a NeoFS API call may return a server response.
|
|
|
|
// Status responses are returned in the result structure, and can be cast
|
|
|
|
// to built-in error instance (or in the returned error if the client is
|
|
|
|
// configured accordingly). Certain statuses can be checked using `apistatus`
|
2022-02-28 10:56:46 +00:00
|
|
|
// and standard `errors` packages. Note that package provides some helper
|
|
|
|
// functions to work with status returns (e.g. IsErrContainerNotFound).
|
2022-01-24 10:33:43 +00:00
|
|
|
// All possible responses are documented in methods, however, some may be
|
|
|
|
// returned from all of them (pay attention to the presence of the pointer sign):
|
|
|
|
// - *apistatus.ServerInternal on internal server error;
|
|
|
|
// - *apistatus.SuccessDefaultV2 on default success.
|
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
|
|
|
|
}
|