From 2bcbd48972f8d07b880063e40485adea34ba37ab Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 16 Nov 2020 11:08:47 +0300 Subject: [PATCH] [#197] sdk: Rename getters of Version type Signed-off-by: Leonard Lyubich --- pkg/client/accounting.go | 2 +- pkg/client/container.go | 12 ++++++------ pkg/client/netmap.go | 4 ++-- pkg/client/object.go | 14 +++++++------- pkg/client/session.go | 2 +- pkg/version.go | 18 +++++++++--------- pkg/version_test.go | 8 ++++---- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pkg/client/accounting.go b/pkg/client/accounting.go index b9e86608..0b553f2c 100644 --- a/pkg/client/accounting.go +++ b/pkg/client/accounting.go @@ -25,7 +25,7 @@ func (c Client) GetSelfBalance(ctx context.Context, opts ...CallOption) (*accoun func (c Client) GetBalance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.getBalanceV2(ctx, owner, opts...) default: diff --git a/pkg/client/container.go b/pkg/client/container.go index a4bc942c..279a340d 100644 --- a/pkg/client/container.go +++ b/pkg/client/container.go @@ -27,7 +27,7 @@ func (c delContainerSignWrapper) SignedDataSize() int { } func (c Client) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.putContainerV2(ctx, cnr, opts...) default: @@ -36,7 +36,7 @@ func (c Client) PutContainer(ctx context.Context, cnr *container.Container, opts } func (c Client) GetContainer(ctx context.Context, id *container.ID, opts ...CallOption) (*container.Container, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.getContainerV2(ctx, id, opts...) default: @@ -45,7 +45,7 @@ func (c Client) GetContainer(ctx context.Context, id *container.ID, opts ...Call } func (c Client) ListContainers(ctx context.Context, owner *owner.ID, opts ...CallOption) ([]*container.ID, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.listContainerV2(ctx, owner, opts...) default: @@ -66,7 +66,7 @@ func (c Client) ListSelfContainers(ctx context.Context, opts ...CallOption) ([]* } func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.delContainerV2(ctx, id, opts...) default: @@ -75,7 +75,7 @@ func (c Client) DeleteContainer(ctx context.Context, id *container.ID, opts ...C } func (c Client) GetEACL(ctx context.Context, id *container.ID, opts ...CallOption) (*eacl.Table, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.getEACLV2(ctx, id, opts...) default: @@ -84,7 +84,7 @@ func (c Client) GetEACL(ctx context.Context, id *container.ID, opts ...CallOptio } func (c Client) SetEACL(ctx context.Context, eacl *eacl.Table, opts ...CallOption) error { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.setEACLV2(ctx, eacl, opts...) default: diff --git a/pkg/client/netmap.go b/pkg/client/netmap.go index ea71b057..81ed41bb 100644 --- a/pkg/client/netmap.go +++ b/pkg/client/netmap.go @@ -14,7 +14,7 @@ import ( // in client constructor via address or open connection. This can be used as a // health check to see if node is alive and responses to requests. func (c Client) EndpointInfo(ctx context.Context, opts ...CallOption) (*netmap.NodeInfo, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: resp, err := c.endpointInfoV2(ctx, opts...) if err != nil { @@ -29,7 +29,7 @@ func (c Client) EndpointInfo(ctx context.Context, opts ...CallOption) (*netmap.N // Epoch returns the epoch number from the local state of the remote host. func (c Client) Epoch(ctx context.Context, opts ...CallOption) (uint64, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: resp, err := c.endpointInfoV2(ctx, opts...) if err != nil { diff --git a/pkg/client/object.go b/pkg/client/object.go index 5d29e5dd..4ce865fc 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -144,7 +144,7 @@ func (p *PutObjectParams) WithPayloadReader(v io.Reader) *PutObjectParams { func (c *Client) PutObject(ctx context.Context, p *PutObjectParams, opts ...CallOption) (*object.ID, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.putObjectV2(ctx, p, opts...) default: @@ -264,7 +264,7 @@ func (p *DeleteObjectParams) WithAddress(v *object.Address) *DeleteObjectParams func (c *Client) DeleteObject(ctx context.Context, p *DeleteObjectParams, opts ...CallOption) error { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.deleteObjectV2(ctx, p, opts...) default: @@ -344,7 +344,7 @@ func (p *GetObjectParams) WithPayloadWriter(w io.Writer) *GetObjectParams { func (c *Client) GetObject(ctx context.Context, p *GetObjectParams, opts ...CallOption) (*object.Object, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.getObjectV2(ctx, p, opts...) default: @@ -477,7 +477,7 @@ func (p *ObjectHeaderParams) WithMainFields() *ObjectHeaderParams { func (c *Client) GetObjectHeader(ctx context.Context, p *ObjectHeaderParams, opts ...CallOption) (*object.Object, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.getObjectHeaderV2(ctx, p, opts...) default: @@ -610,7 +610,7 @@ func (p *RangeDataParams) WithDataWriter(v io.Writer) *RangeDataParams { func (c *Client) ObjectPayloadRangeData(ctx context.Context, p *RangeDataParams, opts ...CallOption) ([]byte, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.objectPayloadRangeV2(ctx, p, opts...) default: @@ -752,7 +752,7 @@ func (c *Client) ObjectPayloadRangeTZ(ctx context.Context, p *RangeChecksumParam func (c *Client) objectPayloadRangeHash(ctx context.Context, p *RangeChecksumParams, opts ...CallOption) (interface{}, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.objectPayloadRangeHashV2(ctx, p, opts...) default: @@ -884,7 +884,7 @@ func (p *SearchObjectParams) WithSearchFilters(v object.SearchFilters) *SearchOb func (c *Client) SearchObject(ctx context.Context, p *SearchObjectParams, opts ...CallOption) ([]*object.ID, error) { // check remote node version - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.searchObjectV2(ctx, p, opts...) default: diff --git a/pkg/client/session.go b/pkg/client/session.go index 51d08ce3..e845b0d3 100644 --- a/pkg/client/session.go +++ b/pkg/client/session.go @@ -12,7 +12,7 @@ import ( ) func (c Client) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*token.SessionToken, error) { - switch c.remoteNode.Version.GetMajor() { + switch c.remoteNode.Version.Major() { case 2: return c.createSessionV2(ctx, expiration, opts...) default: diff --git a/pkg/version.go b/pkg/version.go index c72722dd..1d5f5f72 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -34,8 +34,8 @@ func SDKVersion() *Version { return v } -// GetMajor returns major number of the revision. -func (v *Version) GetMajor() uint32 { +// Major returns major number of the revision. +func (v *Version) Major() uint32 { return (*refs.Version)(v). GetMajor() } @@ -46,8 +46,8 @@ func (v *Version) SetMajor(val uint32) { SetMajor(val) } -// GetMinor returns minor number of the revision. -func (v *Version) GetMinor() uint32 { +// Minor returns minor number of the revision. +func (v *Version) Minor() uint32 { return (*refs.Version)(v). GetMinor() } @@ -64,22 +64,22 @@ func (v *Version) ToV2() *refs.Version { } func (v *Version) String() string { - return fmt.Sprintf("v%d.%d", v.GetMajor(), v.GetMinor()) + return fmt.Sprintf("v%d.%d", v.Major(), v.Minor()) } // IsSupportedVersion returns error if v is not supported by current SDK. func IsSupportedVersion(v *Version) error { - switch mjr := v.GetMajor(); mjr { + switch mjr := v.Major(); mjr { case 2: - switch mnr := v.GetMinor(); mnr { + switch mnr := v.Minor(); mnr { case 0: return nil } } return errors.Errorf("unsupported version %d.%d", - v.GetMajor(), - v.GetMinor(), + v.Major(), + v.Minor(), ) } diff --git a/pkg/version_test.go b/pkg/version_test.go index ce8b8838..73ee6ffb 100644 --- a/pkg/version_test.go +++ b/pkg/version_test.go @@ -14,8 +14,8 @@ func TestNewVersionFromV2(t *testing.T) { v.SetMajor(mjr) v.SetMinor(mnr) - require.Equal(t, mjr, v.GetMajor()) - require.Equal(t, mnr, v.GetMinor()) + require.Equal(t, mjr, v.Major()) + require.Equal(t, mnr, v.Minor()) ver := v.ToV2() @@ -26,8 +26,8 @@ func TestNewVersionFromV2(t *testing.T) { func TestSDKVersion(t *testing.T) { v := SDKVersion() - require.Equal(t, uint32(sdkMjr), v.GetMajor()) - require.Equal(t, uint32(sdkMnr), v.GetMinor()) + require.Equal(t, uint32(sdkMjr), v.Major()) + require.Equal(t, uint32(sdkMnr), v.Minor()) } func TestIsSupportedVersion(t *testing.T) {