apistatus

package
v0.0.0-...-5e759bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 6 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrFromStatus

func ErrFromStatus(st Status) error

ErrFromStatus converts Status instance to error if it is failed. Returns nil on successful Status.

Note: direct assignment may not be compatibility-safe.

func IsSuccessful

func IsSuccessful(st Status) bool

IsSuccessful checks if status is successful.

Note: direct cast may not be compatibility-safe.

func ToStatusV2

func ToStatusV2(st Status) *status.Status

ToStatusV2 converts Status 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 WriteInternalServerErr

func WriteInternalServerErr(x *ServerInternal, err error)

WriteInternalServerErr writes err message to ServerInternal instance.

Types

type ContainerNotFound

type ContainerNotFound struct {
	// contains filtered or unexported fields
}

ContainerNotFound describes status of the failure because of the missing container. Instances provide Status and StatusV2 interfaces.

func (ContainerNotFound) Error

func (x ContainerNotFound) Error() string

func (ContainerNotFound) ToStatusV2

func (x ContainerNotFound) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: CONTAINER_NOT_FOUND;
  • string message: "container not found";
  • details: empty.

type EACLNotFound

type EACLNotFound struct {
	// contains filtered or unexported fields
}

EACLNotFound describes status of the failure because of the missing eACL table. Instances provide Status and StatusV2 interfaces.

func (EACLNotFound) Error

func (x EACLNotFound) Error() string

func (EACLNotFound) ToStatusV2

func (x EACLNotFound) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: EACL_NOT_FOUND;
  • string message: "eACL not found";
  • details: empty.

type LockNonRegularObject

type LockNonRegularObject struct {
	// contains filtered or unexported fields
}

LockNonRegularObject describes status returned on locking the non-regular object. Instances provide Status and StatusV2 interfaces.

func (LockNonRegularObject) Error

func (x LockNonRegularObject) Error() string

func (LockNonRegularObject) ToStatusV2

func (x LockNonRegularObject) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: LOCK_NON_REGULAR_OBJECT;
  • string message: "locking non-regular object is forbidden";
  • details: empty.

type NodeUnderMaintenance

type NodeUnderMaintenance struct {
	// contains filtered or unexported fields
}

NodeUnderMaintenance describes failure status for nodes being under maintenance. Instances provide Status and StatusV2 interfaces.

func (NodeUnderMaintenance) Error

func (x NodeUnderMaintenance) Error() string

Error implements the error interface.

func (NodeUnderMaintenance) Message

func (x NodeUnderMaintenance) Message() string

Message returns status message. Zero status returns empty message. Message should be used for debug purposes only.

See also SetMessage.

func (*NodeUnderMaintenance) SetMessage

func (x *NodeUnderMaintenance) SetMessage(v string)

SetMessage writes signature verification failure message. Message should be used for debug purposes only.

See also Message.

func (NodeUnderMaintenance) ToStatusV2

func (x NodeUnderMaintenance) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: NODE_UNDER_MAINTENANCE;
  • string message: written message via SetMessage or "node is under maintenance" as a default message;
  • details: empty.

type ObjectAccessDenied

type ObjectAccessDenied struct {
	// contains filtered or unexported fields
}

ObjectAccessDenied describes status of the failure because of the access control violation. Instances provide Status and StatusV2 interfaces.

func (ObjectAccessDenied) Error

func (x ObjectAccessDenied) Error() string

func (ObjectAccessDenied) Reason

func (x ObjectAccessDenied) Reason() string

Reason returns human-readable access rejection reason returned by the server. Returns empty value is reason is not presented.

func (ObjectAccessDenied) ToStatusV2

func (x ObjectAccessDenied) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: ACCESS_DENIED;
  • string message: "access to object operation denied";
  • details: empty.

func (*ObjectAccessDenied) WriteReason

func (x *ObjectAccessDenied) WriteReason(reason string)

WriteReason writes human-readable access rejection reason.

type ObjectAlreadyRemoved

type ObjectAlreadyRemoved struct {
	// contains filtered or unexported fields
}

ObjectAlreadyRemoved describes status of the failure because object has been already removed. Instances provide Status and StatusV2 interfaces.

func (ObjectAlreadyRemoved) Error

func (x ObjectAlreadyRemoved) Error() string

func (ObjectAlreadyRemoved) ToStatusV2

func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: OBJECT_ALREADY_REMOVED;
  • string message: "object already removed";
  • details: empty.

type ObjectLocked

type ObjectLocked struct {
	// contains filtered or unexported fields
}

ObjectLocked describes status of the failure because of the locked object. Instances provide Status and StatusV2 interfaces.

func (ObjectLocked) Error

func (x ObjectLocked) Error() string

func (ObjectLocked) ToStatusV2

func (x ObjectLocked) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: LOCKED;
  • string message: "object is locked";
  • details: empty.

type ObjectNotFound

type ObjectNotFound struct {
	// contains filtered or unexported fields
}

ObjectNotFound describes status of the failure because of the missing object. Instances provide Status and StatusV2 interfaces.

func (ObjectNotFound) Error

func (x ObjectNotFound) Error() string

func (ObjectNotFound) ToStatusV2

func (x ObjectNotFound) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: OBJECT_NOT_FOUND;
  • string message: "object not found";
  • details: empty.

type ObjectOutOfRange

type ObjectOutOfRange struct {
	// contains filtered or unexported fields
}

ObjectOutOfRange describes status of the failure because of the incorrect provided object ranges. Instances provide Status and StatusV2 interfaces.

func (ObjectOutOfRange) Error

func (x ObjectOutOfRange) Error() string

func (ObjectOutOfRange) ToStatusV2

func (x ObjectOutOfRange) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: OUT_OF_RANGE;
  • string message: "out of range";
  • details: empty.

type ServerInternal

type ServerInternal struct {
	// contains filtered or unexported fields
}

ServerInternal describes failure statuses related to internal server errors. Instances provide Status and StatusV2 interfaces.

The status is purely informative, the client should not go into details of the error except for debugging needs.

func (ServerInternal) Error

func (x ServerInternal) Error() string

func (ServerInternal) Message

func (x ServerInternal) Message() string

Message returns message describing internal server error.

Message should be used for debug purposes only. By default, it is empty.

func (*ServerInternal) SetMessage

func (x *ServerInternal) SetMessage(msg string)

SetMessage sets message describing internal error.

Message should be used for debug purposes only.

func (ServerInternal) ToStatusV2

func (x ServerInternal) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: INTERNAL;
  • string message: empty;
  • details: empty.

type SessionTokenExpired

type SessionTokenExpired struct {
	// contains filtered or unexported fields
}

SessionTokenExpired describes status of the failure because of the expired session token. Instances provide Status and StatusV2 interfaces.

func (SessionTokenExpired) Error

func (x SessionTokenExpired) Error() string

func (SessionTokenExpired) ToStatusV2

func (x SessionTokenExpired) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: TOKEN_EXPIRED;
  • string message: "expired session token";
  • details: empty.

type SessionTokenNotFound

type SessionTokenNotFound struct {
	// contains filtered or unexported fields
}

SessionTokenNotFound describes status of the failure because of the missing session token. Instances provide Status and StatusV2 interfaces.

func (SessionTokenNotFound) Error

func (x SessionTokenNotFound) Error() string

func (SessionTokenNotFound) ToStatusV2

func (x SessionTokenNotFound) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: TOKEN_NOT_FOUND;
  • string message: "session token not found";
  • details: empty.

type SignatureVerification

type SignatureVerification struct {
	// contains filtered or unexported fields
}

SignatureVerification describes failure status related to signature verification. Instances provide Status and StatusV2 interfaces.

func (SignatureVerification) Error

func (x SignatureVerification) Error() string

func (SignatureVerification) Message

func (x SignatureVerification) Message() string

Message returns status message. Zero status returns empty message. Message should be used for debug purposes only.

See also SetMessage.

func (*SignatureVerification) SetMessage

func (x *SignatureVerification) SetMessage(v string)

SetMessage writes signature verification failure message. Message should be used for debug purposes only.

See also Message.

func (SignatureVerification) ToStatusV2

func (x SignatureVerification) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: SIGNATURE_VERIFICATION_FAIL;
  • string message: written message via SetMessage or "signature verification failed" as a default message;
  • details: empty.

type Status

type Status interface{}

Status defines a variety of FrostFS 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.

To convert statuses into errors and vice versa, use functions ErrToStatus and ErrFromStatus, respectively. ErrFromStatus function returns nil for successful statuses. However, to simplify the check of statuses for success, IsSuccessful function should be used (try to avoid nil comparison). It should be noted that using direct typecasting is not a compatible approach.

To transport statuses using the FrostFS API V2 protocol, see StatusV2 interface and FromStatusV2 and ToStatusV2 functions.

func ErrToStatus

func ErrToStatus(err error) Status

ErrToStatus converts the error instance to Status instance.

Note: direct assignment may not be compatibility-safe.

func FromStatusV2

func FromStatusV2(st *status.Status) Status

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.

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:

  • status.OK: *SuccessDefaultV2 (this also includes nil argument).

Common failures:

  • status.Internal: *ServerInternal;
  • status.SignatureVerificationFail: *SignatureVerification.

Object failures:

  • object.StatusLocked: *ObjectLocked;
  • object.StatusLockNonRegularObject: *LockNonRegularObject.
  • object.StatusAccessDenied: *ObjectAccessDenied.

type StatusV2

type StatusV2 interface {
	Status

	// ToStatusV2 returns the status as github.com/TrueCloudLab/frostfs-api-go/v2/status.Status message structure.
	ToStatusV2() *status.Status
}

StatusV2 defines a variety of Status instances compatible with FrostFS API V2 protocol.

Note: it is not recommended to use this type directly, it is intended for documentation of the library functionality.

type SuccessDefaultV2

type SuccessDefaultV2 struct {
	// contains filtered or unexported fields
}

SuccessDefaultV2 represents Status instance of default success. Implements StatusV2.

func (SuccessDefaultV2) ToStatusV2

func (x SuccessDefaultV2) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: OK;
  • string message: empty;
  • details: empty.

type WrongMagicNumber

type WrongMagicNumber struct {
	// contains filtered or unexported fields
}

WrongMagicNumber describes failure status related to incorrect network magic. Instances provide Status and StatusV2 interfaces.

func (WrongMagicNumber) CorrectMagic

func (x WrongMagicNumber) CorrectMagic() (magic uint64, ok int8)

CorrectMagic returns network magic returned by the server. Second value indicates presence status:

  • -1 if number is presented in incorrect format
  • 0 if number is not presented
  • +1 otherwise

func (WrongMagicNumber) Error

func (x WrongMagicNumber) Error() string

func (WrongMagicNumber) ToStatusV2

func (x WrongMagicNumber) ToStatusV2() *status.Status

ToStatusV2 implements StatusV2 interface method. If the value was returned by FromStatusV2, returns the source message. Otherwise, returns message with

  • code: WRONG_MAGIC_NUMBER;
  • string message: empty;
  • details: empty.

func (*WrongMagicNumber) WriteCorrectMagic

func (x *WrongMagicNumber) WriteCorrectMagic(magic uint64)

WriteCorrectMagic writes correct network magic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL