From 22ff96ad44f7215921e2d0d253cc921c1c4f0643 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Tue, 23 May 2023 07:32:33 +0400 Subject: [PATCH] client: Remove status.Status type Signed-off-by: Evgenii Baidakov --- client/status/common.go | 8 ++++---- client/status/container.go | 4 ++-- client/status/object.go | 10 +++++----- client/status/session.go | 4 ++-- client/status/status.go | 15 --------------- client/status/success.go | 2 +- client/status/unrecognized.go | 2 +- client/status/v2.go | 24 +++++++++++------------- client/status/v2_test.go | 30 +++++++++++++++--------------- 9 files changed, 41 insertions(+), 58 deletions(-) delete mode 100644 client/status/status.go diff --git a/client/status/common.go b/client/status/common.go index ec01eb9..a705a8e 100644 --- a/client/status/common.go +++ b/client/status/common.go @@ -27,7 +27,7 @@ var ( ) // ServerInternal describes failure statuses related to internal server errors. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. // // The status is purely informative, the client should not go into details of the error except for debugging needs. type ServerInternal struct { @@ -87,7 +87,7 @@ func WriteInternalServerErr(x *ServerInternal, err error) { } // WrongMagicNumber describes failure status related to incorrect network magic. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type WrongMagicNumber struct { v2 status.Status } @@ -165,7 +165,7 @@ func (x WrongMagicNumber) CorrectMagic() (magic uint64, ok int8) { } // SignatureVerification describes failure status related to signature verification. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type SignatureVerification struct { v2 status.Status } @@ -233,7 +233,7 @@ func (x SignatureVerification) Message() string { } // NodeUnderMaintenance describes failure status for nodes being under maintenance. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type NodeUnderMaintenance struct { v2 status.Status } diff --git a/client/status/container.go b/client/status/container.go index c643123..e5bd8d2 100644 --- a/client/status/container.go +++ b/client/status/container.go @@ -17,7 +17,7 @@ var ( ) // ContainerNotFound describes status of the failure because of the missing container. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type ContainerNotFound struct { v2 status.Status } @@ -65,7 +65,7 @@ func (x ContainerNotFound) ToStatusV2() *status.Status { // EACLNotFound describes status of the failure because of the missing eACL // table. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type EACLNotFound struct { v2 status.Status } diff --git a/client/status/object.go b/client/status/object.go index 2726088..4cf8f5c 100644 --- a/client/status/object.go +++ b/client/status/object.go @@ -29,7 +29,7 @@ var ( ) // ObjectLocked describes status of the failure because of the locked object. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type ObjectLocked struct { v2 status.Status } @@ -76,7 +76,7 @@ func (x ObjectLocked) ToStatusV2() *status.Status { } // LockNonRegularObject describes status returned on locking the non-regular object. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type LockNonRegularObject struct { v2 status.Status } @@ -123,7 +123,7 @@ func (x LockNonRegularObject) ToStatusV2() *status.Status { } // ObjectAccessDenied describes status of the failure because of the access control violation. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type ObjectAccessDenied struct { v2 status.Status } @@ -181,7 +181,7 @@ func (x ObjectAccessDenied) Reason() string { } // ObjectNotFound describes status of the failure because of the missing object. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type ObjectNotFound struct { v2 status.Status } @@ -276,7 +276,7 @@ func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status { // ObjectOutOfRange describes status of the failure because of the incorrect // provided object ranges. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type ObjectOutOfRange struct { v2 status.Status } diff --git a/client/status/session.go b/client/status/session.go index a6a04c0..1ce8145 100644 --- a/client/status/session.go +++ b/client/status/session.go @@ -17,7 +17,7 @@ var ( ) // SessionTokenNotFound describes status of the failure because of the missing session token. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type SessionTokenNotFound struct { v2 status.Status } @@ -64,7 +64,7 @@ func (x SessionTokenNotFound) ToStatusV2() *status.Status { } // SessionTokenExpired describes status of the failure because of the expired session token. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type SessionTokenExpired struct { v2 status.Status } diff --git a/client/status/status.go b/client/status/status.go deleted file mode 100644 index ea352bf..0000000 --- a/client/status/status.go +++ /dev/null @@ -1,15 +0,0 @@ -package apistatus - -// Status defines a variety of NeoFS API status returns. -// -// All statuses are split into two disjoint subsets: successful and failed, and: -// - statuses that implement the build-in error interface are considered failed statuses; -// - all other value types are considered successes (nil is a default success). -// -// In Go code type of success can be determined by a type switch, failure - by a switch with [errors.As] calls. -// Nil should be considered as a success, and default switch section - as an unrecognized Status. -// -// It should be noted that using direct typecasting is not a compatible approach. -// -// To transport statuses using the NeoFS API V2 protocol, see [StatusV2] interface and [FromStatusV2] and [ToStatusV2] functions. -type Status any diff --git a/client/status/success.go b/client/status/success.go index bd9ee82..80fd03b 100644 --- a/client/status/success.go +++ b/client/status/success.go @@ -4,7 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/status" ) -// SuccessDefaultV2 represents Status instance of default success. Implements StatusV2. +// SuccessDefaultV2 represents instance of default success. Implements [StatusV2]. type SuccessDefaultV2 struct { isNil bool diff --git a/client/status/unrecognized.go b/client/status/unrecognized.go index a48ee44..6a67309 100644 --- a/client/status/unrecognized.go +++ b/client/status/unrecognized.go @@ -9,7 +9,7 @@ import ( var ErrUnrecognizedStatusV2 UnrecognizedStatusV2 // UnrecognizedStatusV2 describes status of the uncertain failure. -// Instances provide [Status], [StatusV2] and error interfaces. +// Instances provide [StatusV2] and error interfaces. type UnrecognizedStatusV2 struct { v2 status.Status } diff --git a/client/status/v2.go b/client/status/v2.go index 34ce68a..9a01bff 100644 --- a/client/status/v2.go +++ b/client/status/v2.go @@ -9,22 +9,20 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/status" ) -// StatusV2 defines a variety of Status instances compatible with NeoFS API V2 protocol. +// StatusV2 defines a variety of status instances compatible with NeoFS API V2 protocol. // // Note: it is not recommended to use this type directly, it is intended for documentation of the library functionality. type StatusV2 interface { - Status - // ToStatusV2 returns the status as github.com/nspcc-dev/neofs-api-go/v2/status.Status message structure. ToStatusV2() *status.Status } -// FromStatusV2 converts status.Status message structure to Status instance. Inverse to ToStatusV2 operation. +// FromStatusV2 converts [status.Status] message structure to status instance. Inverse to [ToStatusV2] operation. // -// If result is not nil, it implements StatusV2. This fact should be taken into account only when passing -// the result to the inverse function ToStatusV2, casts are not compatibility-safe. +// If result is not nil, it implements [StatusV2]. This fact should be taken into account only when passing +// the result to the inverse function [ToStatusV2], casts are not compatibility-safe. // -// Below is the mapping of return codes to Status instance types (with a description of parsing details). +// Below is the mapping of return codes to status instance types (with a description of parsing details). // Note: notice if the return type is a pointer. // // Successes: @@ -51,7 +49,7 @@ type StatusV2 interface { // Session failures: // - [session.StatusTokenNotFound]: *[SessionTokenNotFound]; // - [session.StatusTokenExpired]: *[SessionTokenExpired]; -func FromStatusV2(st *status.Status) Status { +func FromStatusV2(st *status.Status) any { var decoder interface { fromStatusV2(*status.Status) } @@ -116,12 +114,12 @@ func FromStatusV2(st *status.Status) Status { return decoder } -// ToStatusV2 converts Status instance to status.Status message structure. Inverse to FromStatusV2 operation. +// ToStatusV2 converts instance to status.Status message structure. Inverse to [FromStatusV2] operation. // -// If argument is the StatusV2 instance, it is converted directly. -// Otherwise, successes are converted with status.OK code w/o details and message, -// failures - with status.Internal and error text message w/o details. -func ToStatusV2(st Status) *status.Status { +// If argument is the [StatusV2] instance, it is converted directly. +// Otherwise, successes are converted with [status.OK] code w/o details and message, +// failures - with [status.Internal] and error text message w/o details. +func ToStatusV2(st any) *status.Status { if v, ok := st.(StatusV2); ok { return v.ToStatusV2() } diff --git a/client/status/v2_test.go b/client/status/v2_test.go index 0eb9dc8..9c5b803 100644 --- a/client/status/v2_test.go +++ b/client/status/v2_test.go @@ -9,7 +9,7 @@ import ( ) func TestFromStatusV2(t *testing.T) { - type statusConstructor func() apistatus.Status + type statusConstructor func() any for _, testItem := range [...]struct { status any // Status or statusConstructor @@ -44,7 +44,7 @@ func TestFromStatusV2(t *testing.T) { codeV2: 0, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { st := new(apistatus.ServerInternal) st.SetMessage("internal error message") @@ -58,7 +58,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { st := new(apistatus.WrongMagicNumber) st.WriteCorrectMagic(322) @@ -72,7 +72,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.ObjectLocked) }), codeV2: 2050, @@ -83,7 +83,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.LockNonRegularObject) }), codeV2: 2051, @@ -94,7 +94,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { st := new(apistatus.ObjectAccessDenied) st.WriteReason("any reason") @@ -108,7 +108,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.ObjectNotFound) }), codeV2: 2049, @@ -119,7 +119,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.ObjectAlreadyRemoved) }), codeV2: 2052, @@ -130,7 +130,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: statusConstructor(func() apistatus.Status { + status: statusConstructor(func() any { return new(apistatus.ObjectOutOfRange) }), codeV2: 2053, @@ -141,7 +141,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.ContainerNotFound) }), codeV2: 3072, @@ -152,7 +152,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.EACLNotFound) }), codeV2: 3073, @@ -163,7 +163,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.SessionTokenNotFound) }), codeV2: 4096, @@ -174,7 +174,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.SessionTokenExpired) }), codeV2: 4097, @@ -185,7 +185,7 @@ func TestFromStatusV2(t *testing.T) { }, }, { - status: (statusConstructor)(func() apistatus.Status { + status: (statusConstructor)(func() any { return new(apistatus.NodeUnderMaintenance) }), codeV2: 1027, @@ -196,7 +196,7 @@ func TestFromStatusV2(t *testing.T) { }, }, } { - var st apistatus.Status + var st any if cons, ok := testItem.status.(statusConstructor); ok { st = cons()