client: Remove status.Status type

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
Evgenii Baidakov 2023-05-23 07:32:33 +04:00
parent 277b8f7de4
commit 22ff96ad44
No known key found for this signature in database
GPG key ID: 8733EE3D72CDB4DE
9 changed files with 41 additions and 58 deletions

View file

@ -27,7 +27,7 @@ var (
) )
// ServerInternal describes failure statuses related to internal server errors. // 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. // The status is purely informative, the client should not go into details of the error except for debugging needs.
type ServerInternal struct { type ServerInternal struct {
@ -87,7 +87,7 @@ func WriteInternalServerErr(x *ServerInternal, err error) {
} }
// WrongMagicNumber describes failure status related to incorrect network magic. // 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 { type WrongMagicNumber struct {
v2 status.Status v2 status.Status
} }
@ -165,7 +165,7 @@ func (x WrongMagicNumber) CorrectMagic() (magic uint64, ok int8) {
} }
// SignatureVerification describes failure status related to signature verification. // SignatureVerification describes failure status related to signature verification.
// Instances provide [Status], [StatusV2] and error interfaces. // Instances provide [StatusV2] and error interfaces.
type SignatureVerification struct { type SignatureVerification struct {
v2 status.Status v2 status.Status
} }
@ -233,7 +233,7 @@ func (x SignatureVerification) Message() string {
} }
// NodeUnderMaintenance describes failure status for nodes being under maintenance. // 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 { type NodeUnderMaintenance struct {
v2 status.Status v2 status.Status
} }

View file

@ -17,7 +17,7 @@ var (
) )
// ContainerNotFound describes status of the failure because of the missing container. // 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 { type ContainerNotFound struct {
v2 status.Status v2 status.Status
} }
@ -65,7 +65,7 @@ func (x ContainerNotFound) ToStatusV2() *status.Status {
// EACLNotFound describes status of the failure because of the missing eACL // EACLNotFound describes status of the failure because of the missing eACL
// table. // table.
// Instances provide [Status], [StatusV2] and error interfaces. // Instances provide [StatusV2] and error interfaces.
type EACLNotFound struct { type EACLNotFound struct {
v2 status.Status v2 status.Status
} }

View file

@ -29,7 +29,7 @@ var (
) )
// ObjectLocked describes status of the failure because of the locked object. // 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 { type ObjectLocked struct {
v2 status.Status v2 status.Status
} }
@ -76,7 +76,7 @@ func (x ObjectLocked) ToStatusV2() *status.Status {
} }
// LockNonRegularObject describes status returned on locking the non-regular object. // 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 { type LockNonRegularObject struct {
v2 status.Status 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. // 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 { type ObjectAccessDenied struct {
v2 status.Status v2 status.Status
} }
@ -181,7 +181,7 @@ func (x ObjectAccessDenied) Reason() string {
} }
// ObjectNotFound describes status of the failure because of the missing object. // 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 { type ObjectNotFound struct {
v2 status.Status v2 status.Status
} }
@ -276,7 +276,7 @@ func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
// ObjectOutOfRange describes status of the failure because of the incorrect // ObjectOutOfRange describes status of the failure because of the incorrect
// provided object ranges. // provided object ranges.
// Instances provide [Status], [StatusV2] and error interfaces. // Instances provide [StatusV2] and error interfaces.
type ObjectOutOfRange struct { type ObjectOutOfRange struct {
v2 status.Status v2 status.Status
} }

View file

@ -17,7 +17,7 @@ var (
) )
// SessionTokenNotFound describes status of the failure because of the missing session token. // 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 { type SessionTokenNotFound struct {
v2 status.Status 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. // 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 { type SessionTokenExpired struct {
v2 status.Status v2 status.Status
} }

View file

@ -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

View file

@ -4,7 +4,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/status" "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 { type SuccessDefaultV2 struct {
isNil bool isNil bool

View file

@ -9,7 +9,7 @@ import (
var ErrUnrecognizedStatusV2 UnrecognizedStatusV2 var ErrUnrecognizedStatusV2 UnrecognizedStatusV2
// UnrecognizedStatusV2 describes status of the uncertain failure. // UnrecognizedStatusV2 describes status of the uncertain failure.
// Instances provide [Status], [StatusV2] and error interfaces. // Instances provide [StatusV2] and error interfaces.
type UnrecognizedStatusV2 struct { type UnrecognizedStatusV2 struct {
v2 status.Status v2 status.Status
} }

View file

@ -9,22 +9,20 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/status" "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. // Note: it is not recommended to use this type directly, it is intended for documentation of the library functionality.
type StatusV2 interface { type StatusV2 interface {
Status
// ToStatusV2 returns the status as github.com/nspcc-dev/neofs-api-go/v2/status.Status message structure. // ToStatusV2 returns the status as github.com/nspcc-dev/neofs-api-go/v2/status.Status message structure.
ToStatusV2() *status.Status 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 // 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. // 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. // Note: notice if the return type is a pointer.
// //
// Successes: // Successes:
@ -51,7 +49,7 @@ type StatusV2 interface {
// Session failures: // Session failures:
// - [session.StatusTokenNotFound]: *[SessionTokenNotFound]; // - [session.StatusTokenNotFound]: *[SessionTokenNotFound];
// - [session.StatusTokenExpired]: *[SessionTokenExpired]; // - [session.StatusTokenExpired]: *[SessionTokenExpired];
func FromStatusV2(st *status.Status) Status { func FromStatusV2(st *status.Status) any {
var decoder interface { var decoder interface {
fromStatusV2(*status.Status) fromStatusV2(*status.Status)
} }
@ -116,12 +114,12 @@ func FromStatusV2(st *status.Status) Status {
return decoder 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. // If argument is the [StatusV2] instance, it is converted directly.
// Otherwise, successes are converted with status.OK code w/o details and message, // Otherwise, successes are converted with [status.OK] code w/o details and message,
// failures - with status.Internal and error text message w/o details. // failures - with [status.Internal] and error text message w/o details.
func ToStatusV2(st Status) *status.Status { func ToStatusV2(st any) *status.Status {
if v, ok := st.(StatusV2); ok { if v, ok := st.(StatusV2); ok {
return v.ToStatusV2() return v.ToStatusV2()
} }

View file

@ -9,7 +9,7 @@ import (
) )
func TestFromStatusV2(t *testing.T) { func TestFromStatusV2(t *testing.T) {
type statusConstructor func() apistatus.Status type statusConstructor func() any
for _, testItem := range [...]struct { for _, testItem := range [...]struct {
status any // Status or statusConstructor status any // Status or statusConstructor
@ -44,7 +44,7 @@ func TestFromStatusV2(t *testing.T) {
codeV2: 0, codeV2: 0,
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
st := new(apistatus.ServerInternal) st := new(apistatus.ServerInternal)
st.SetMessage("internal error message") 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 := new(apistatus.WrongMagicNumber)
st.WriteCorrectMagic(322) 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) return new(apistatus.ObjectLocked)
}), }),
codeV2: 2050, codeV2: 2050,
@ -83,7 +83,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.LockNonRegularObject) return new(apistatus.LockNonRegularObject)
}), }),
codeV2: 2051, 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 := new(apistatus.ObjectAccessDenied)
st.WriteReason("any reason") 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) return new(apistatus.ObjectNotFound)
}), }),
codeV2: 2049, codeV2: 2049,
@ -119,7 +119,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.ObjectAlreadyRemoved) return new(apistatus.ObjectAlreadyRemoved)
}), }),
codeV2: 2052, codeV2: 2052,
@ -130,7 +130,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: statusConstructor(func() apistatus.Status { status: statusConstructor(func() any {
return new(apistatus.ObjectOutOfRange) return new(apistatus.ObjectOutOfRange)
}), }),
codeV2: 2053, codeV2: 2053,
@ -141,7 +141,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.ContainerNotFound) return new(apistatus.ContainerNotFound)
}), }),
codeV2: 3072, codeV2: 3072,
@ -152,7 +152,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.EACLNotFound) return new(apistatus.EACLNotFound)
}), }),
codeV2: 3073, codeV2: 3073,
@ -163,7 +163,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.SessionTokenNotFound) return new(apistatus.SessionTokenNotFound)
}), }),
codeV2: 4096, codeV2: 4096,
@ -174,7 +174,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.SessionTokenExpired) return new(apistatus.SessionTokenExpired)
}), }),
codeV2: 4097, codeV2: 4097,
@ -185,7 +185,7 @@ func TestFromStatusV2(t *testing.T) {
}, },
}, },
{ {
status: (statusConstructor)(func() apistatus.Status { status: (statusConstructor)(func() any {
return new(apistatus.NodeUnderMaintenance) return new(apistatus.NodeUnderMaintenance)
}), }),
codeV2: 1027, 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 { if cons, ok := testItem.status.(statusConstructor); ok {
st = cons() st = cons()