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.
// 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
}

View file

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

View file

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

View file

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

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"
)
// SuccessDefaultV2 represents Status instance of default success. Implements StatusV2.
// SuccessDefaultV2 represents instance of default success. Implements [StatusV2].
type SuccessDefaultV2 struct {
isNil bool

View file

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

View file

@ -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()
}

View file

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