forked from TrueCloudLab/frostfs-sdk-go
[#48] client: Remove ctx == nil
checks
Much less useful after we made context to be passed explicitly. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
55b06cd764
commit
1bfa9ecdb0
17 changed files with 9 additions and 71 deletions
|
@ -52,10 +52,7 @@ func (x ResBalanceGet) Amount() accounting.Decimal {
|
||||||
// Return statuses:
|
// Return statuses:
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalanceGet, error) {
|
func (c *Client) BalanceGet(ctx context.Context, prm PrmBalanceGet) (*ResBalanceGet, error) {
|
||||||
switch {
|
if !prm.accountSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.accountSet:
|
|
||||||
return nil, errorAccountNotSet
|
return nil, errorAccountNotSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ func writeXHeadersToMeta(xHeaders []string, h *v2session.RequestMetaHeader) {
|
||||||
|
|
||||||
// error messages.
|
// error messages.
|
||||||
var (
|
var (
|
||||||
errorMissingContext = errors.New("missing context")
|
|
||||||
errorMissingContainer = errors.New("missing container")
|
errorMissingContainer = errors.New("missing container")
|
||||||
errorMissingObject = errors.New("missing object")
|
errorMissingObject = errors.New("missing object")
|
||||||
errorAccountNotSet = errors.New("account not set")
|
errorAccountNotSet = errors.New("account not set")
|
||||||
|
|
|
@ -72,10 +72,7 @@ type ResContainerDelete struct {
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*ResContainerDelete, error) {
|
func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*ResContainerDelete, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.idSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.idSet:
|
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,7 @@ func (x ResContainerEACL) Table() eacl.Table {
|
||||||
// - *apistatus.EACLNotFound.
|
// - *apistatus.EACLNotFound.
|
||||||
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
|
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.idSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.idSet:
|
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,7 @@ func (x ResContainerGet) Container() container.Container {
|
||||||
// - global (see Client docs);
|
// - global (see Client docs);
|
||||||
// - *apistatus.ContainerNotFound.
|
// - *apistatus.ContainerNotFound.
|
||||||
func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResContainerGet, error) {
|
func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResContainerGet, error) {
|
||||||
switch {
|
if !prm.idSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.idSet:
|
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,7 @@ func (x ResContainerList) Containers() []cid.ID {
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResContainerList, error) {
|
func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResContainerList, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.ownerSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.ownerSet:
|
|
||||||
return nil, errorAccountNotSet
|
return nil, errorAccountNotSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,10 +82,7 @@ func (x ResContainerPut) ID() cid.ID {
|
||||||
// nolint: funlen
|
// nolint: funlen
|
||||||
func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResContainerPut, error) {
|
func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResContainerPut, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.cnrSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.cnrSet:
|
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,7 @@ type ResContainerSetEACL struct {
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) (*ResContainerSetEACL, error) {
|
func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) (*ResContainerSetEACL, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.tableSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.tableSet:
|
|
||||||
return nil, errorEACLTableNotSet
|
return nil, errorEACLTableNotSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,7 @@ type ResAnnounceSpace struct {
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) (*ResAnnounceSpace, error) {
|
func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) (*ResAnnounceSpace, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if len(prm.announcements) == 0 {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case len(prm.announcements) == 0:
|
|
||||||
return nil, errorMissingAnnouncements
|
return nil, errorMissingAnnouncements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,11 +56,6 @@ func (x ResEndpointInfo) NodeInfo() netmap.NodeInfo {
|
||||||
// Return statuses:
|
// Return statuses:
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
|
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
|
||||||
// check context
|
|
||||||
if ctx == nil {
|
|
||||||
return nil, errorMissingContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2netmap.LocalNodeInfoRequest
|
var req v2netmap.LocalNodeInfoRequest
|
||||||
|
|
||||||
|
@ -153,11 +148,6 @@ func (x ResNetworkInfo) Info() netmap.NetworkInfo {
|
||||||
// Return statuses:
|
// Return statuses:
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
|
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
|
||||||
// check context
|
|
||||||
if ctx == nil {
|
|
||||||
return nil, errorMissingContext
|
|
||||||
}
|
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2netmap.NetworkInfoRequest
|
var req v2netmap.NetworkInfoRequest
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,6 @@ func (x ResObjectDelete) Tombstone() oid.ID {
|
||||||
// - *apistatus.SessionTokenExpired.
|
// - *apistatus.SessionTokenExpired.
|
||||||
func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObjectDelete, error) {
|
func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObjectDelete, error) {
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.addr.GetContainerID() == nil:
|
case prm.addr.GetContainerID() == nil:
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
case prm.addr.GetObjectID() == nil:
|
case prm.addr.GetObjectID() == nil:
|
||||||
|
|
|
@ -301,8 +301,6 @@ func (x *ObjectReader) Read(p []byte) (int, error) {
|
||||||
func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectReader, error) {
|
func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectReader, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.addr.GetContainerID() == nil:
|
case prm.addr.GetContainerID() == nil:
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
case prm.addr.GetObjectID() == nil:
|
case prm.addr.GetObjectID() == nil:
|
||||||
|
@ -416,8 +414,6 @@ func (x *ResObjectHead) ReadHeader(dst *object.Object) bool {
|
||||||
// - *apistatus.SessionTokenExpired.
|
// - *apistatus.SessionTokenExpired.
|
||||||
func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectHead, error) {
|
func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectHead, error) {
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.addr.GetContainerID() == nil:
|
case prm.addr.GetContainerID() == nil:
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
case prm.addr.GetObjectID() == nil:
|
case prm.addr.GetObjectID() == nil:
|
||||||
|
@ -668,8 +664,6 @@ func (x *ObjectRangeReader) Read(p []byte) (int, error) {
|
||||||
func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*ObjectRangeReader, error) {
|
func (c *Client) ObjectRangeInit(ctx context.Context, prm PrmObjectRange) (*ObjectRangeReader, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.addr.GetContainerID() == nil:
|
case prm.addr.GetContainerID() == nil:
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
case prm.addr.GetObjectID() == nil:
|
case prm.addr.GetObjectID() == nil:
|
||||||
|
|
|
@ -166,8 +166,6 @@ func (x ResObjectHash) Checksums() [][]byte {
|
||||||
// - *apistatus.SessionTokenExpired.
|
// - *apistatus.SessionTokenExpired.
|
||||||
func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) {
|
func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) {
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.addr.GetContainerID() == nil:
|
case prm.addr.GetContainerID() == nil:
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
case prm.addr.GetObjectID() == nil:
|
case prm.addr.GetObjectID() == nil:
|
||||||
|
|
|
@ -245,11 +245,6 @@ func (x *ObjectWriter) Close() (*ResObjectPut, error) {
|
||||||
// Returns an error if parameters are set incorrectly.
|
// Returns an error if parameters are set incorrectly.
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*ObjectWriter, error) {
|
func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*ObjectWriter, error) {
|
||||||
// check parameters
|
|
||||||
if ctx == nil {
|
|
||||||
return nil, errorMissingContext
|
|
||||||
}
|
|
||||||
|
|
||||||
var w ObjectWriter
|
var w ObjectWriter
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
|
@ -222,10 +222,7 @@ func (x *ObjectListReader) Close() (*ResObjectSearch, error) {
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) {
|
func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
if !prm.cnrSet {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case !prm.cnrSet:
|
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,6 @@ type ResAnnounceLocalTrust struct {
|
||||||
func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTrust) (*ResAnnounceLocalTrust, error) {
|
func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTrust) (*ResAnnounceLocalTrust, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.epoch == 0:
|
case prm.epoch == 0:
|
||||||
return nil, errorZeroEpoch
|
return nil, errorZeroEpoch
|
||||||
case len(prm.trusts) == 0:
|
case len(prm.trusts) == 0:
|
||||||
|
@ -154,8 +152,6 @@ type ResAnnounceIntermediateTrust struct {
|
||||||
func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm PrmAnnounceIntermediateTrust) (*ResAnnounceIntermediateTrust, error) {
|
func (c *Client) AnnounceIntermediateTrust(ctx context.Context, prm PrmAnnounceIntermediateTrust) (*ResAnnounceIntermediateTrust, error) {
|
||||||
// check parameters
|
// check parameters
|
||||||
switch {
|
switch {
|
||||||
case ctx == nil:
|
|
||||||
return nil, errorMissingContext
|
|
||||||
case prm.epoch == 0:
|
case prm.epoch == 0:
|
||||||
return nil, errorZeroEpoch
|
return nil, errorZeroEpoch
|
||||||
case !prm.trustSet:
|
case !prm.trustSet:
|
||||||
|
|
|
@ -78,11 +78,6 @@ func (x ResSessionCreate) PublicKey() []byte {
|
||||||
// Return statuses:
|
// Return statuses:
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResSessionCreate, error) {
|
func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResSessionCreate, error) {
|
||||||
// check context
|
|
||||||
if ctx == nil {
|
|
||||||
return nil, errorMissingContext
|
|
||||||
}
|
|
||||||
|
|
||||||
ownerKey := c.prm.key.PublicKey
|
ownerKey := c.prm.key.PublicKey
|
||||||
if prm.keySet {
|
if prm.keySet {
|
||||||
ownerKey = prm.key.PublicKey
|
ownerKey = prm.key.PublicKey
|
||||||
|
|
Loading…
Reference in a new issue