api

package
v0.0.0-...-ad012dd Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package api provides types for common objects required during calls to remote Synology instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DescribeError

func DescribeError(code int, summaries ...ErrorSummary) string

DescribeError translates error code to human-readable summary text. It accepts error code and number of summary maps to look in. First summary with this code wins.

Types

type ErrorDescriber

type ErrorDescriber interface {
	// ErrorSummaries returns information about all known errors.
	ErrorSummaries() []ErrorSummary
}

ErrorDescriber defines interface to report all known errors to particular object.

type ErrorFields

type ErrorFields map[string]interface{}

ErrorFields defines extra fields for particular detailed error.

type ErrorItem

type ErrorItem struct {
	Code    int
	Summary string
	Details ErrorFields
}

ErrorItem defines detailed request error.

func (*ErrorItem) UnmarshalJSON

func (ei *ErrorItem) UnmarshalJSON(b []byte) error

UnmarshalJSON fullfills Unmarshaler interface for JSON objects.

type ErrorSummary

type ErrorSummary map[int]string

ErrorSummary is a simple mapping of code->text to translate error codes to readable text.

var GlobalErrors ErrorSummary = ErrorSummary{
	100: "Unknown error",
	101: "No parameter of API, method or version",
	102: "The requested API does not exist",
	103: "The requested method does not exist",
	104: "The requested version does not support the functionality",
	105: "The logged in session does not have permission",
	106: "Session timeout",
	107: "Session interrupted by duplicate login",
	119: "SID not found",
}

GlobalErrors holds mapping of global errors not related to particular API endpoint.

type GenericResponse

type GenericResponse struct {
	Success bool
	Data    interface{}
	Error   SynologyError
}

GenericResponse is a concrete Response implementation. It is a generic struct with common to all Synology response fields.

type Request

type Request interface{}

Request defines a contract for all Request implementations.

type Response

type Response interface {
	ErrorDescriber

	// GetError returns the latest error associated with response, if any.
	GetError() SynologyError

	// SetError sets error object for the current response.
	SetError(SynologyError)

	// Success reports whether the current request was successful.
	Success() bool
}

Response defines an interface for all responses from Synology API.

type SynologyError

type SynologyError struct {
	Code    int
	Summary string
	// Errors is a collection of detailed errors for a concrete API request.
	Errors []ErrorItem
}

SynologyError defines a structure for error object returned by Synology API. It is a high-level error for a particular API family.

func (SynologyError) Error

func (se SynologyError) Error() string

Error satisfies error interface for SynologyError type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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