core

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: GPL-3.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ResponseReadError occurs when error happened while we tried to
	// read the response.
	ResponseReadError = "Error reading body"
	// ResponseReadBodyError occurs when error happened while we tried to
	// read the body of the response.
	ResponseReadBodyError = "Error reading body"
	// ErrorResponseParseError occurs when the response was an error,
	// but something went wrong with parsing it as an Error.
	ErrorResponseParseError = "Error response parse error"
	// UndefinedRequiredField occurs when a mandatory field is not defined
	// in a request.
	UndefinedRequiredField = "Undefined required field"
	// OutOfRangeError is a template error where a given value
	// has to be in a given range.
	OutOfRangeError = "Out of range [%d..%d]"
	// ExceedMaximumLengthError occurs when a parameter is longer
	// than expected on an endpoint.
	ExceedMaximumLengthError = "Value is too long"
)

Variables

This section is empty.

Functions

func NewRangeError

func NewRangeError(from, to int64) string

NewRangeError generates an error message for an OutOfRangeError.

func StringValue

func StringValue(s String) string

StringValue returns the value of a core.String as string. If the value is nil, it returns with an empty string.

Types

type BaseRequest

type BaseRequest interface {
	Validate() error
}

BaseRequest is used to add simple functionality to all requests. Each request is responsible for its own validation by implementing this interface.

type DataSize

type DataSize uint64

DataSize is an alias for uint64 with extra functions for easier conversion between sizes. The value should contain bytes.

I know I should use github.com/catalint/datasize or something similar, but I don't know if I want to support that later on or if I want to add extra functionality to it.

func (DataSize) Bytes

func (d DataSize) Bytes() uint64

Bytes returns with its value as a uint64.

func (DataSize) Gigabytes

func (d DataSize) Gigabytes() float64

Gigabytes returns with the calculated gigabytes value as a float.

func (DataSize) Kilobytes

func (d DataSize) Kilobytes() float64

Kilobytes returns with the calculated kilobytes value as a float.

func (DataSize) Megabytes

func (d DataSize) Megabytes() float64

Megabytes returns with the calculated megabytes value as a float.

func (DataSize) Terabytes

func (d DataSize) Terabytes() float64

Terabytes returns with the calculated terabytes value as a float.

type EmptyResponse

type EmptyResponse struct{}

EmptyResponse is an empty struct. The main reason behind this empty response is that there are endpoints where the return body is empty, but they have 2xx response code, therefore it was successful.

type EndpointNotFound added in v1.0.1

type EndpointNotFound struct {
	Endpoint string
}

EndpointNotFound happens when the requested endpoint returs with 404 error code.

func (EndpointNotFound) Error added in v1.0.1

func (e EndpointNotFound) Error() string

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	ID      string `json:"id"`
	Kind    string `json:"kind"`
	Info    struct {
		Param  string `json:"param"`
		Reason string `json:"reason"`
	} `json:"info"`
}

ErrorResponse represents any kind of Error responses from Misskey.

type ErrorResponseWrapper

type ErrorResponseWrapper struct {
	Error json.RawMessage `json:"error"`
}

ErrorResponseWrapper is the wrapper for error responses.

type FieldError

type FieldError struct {
	Name  string
	Issue string
}

FieldError is the detailed error on a given field in a request.

type HTTPClient added in v1.0.1

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is a simple intreface for http.Client.

type InvalidFieldReferenceError

type InvalidFieldReferenceError struct {
	Name      string
	Type      string
	Reference string
}

InvalidFieldReferenceError occurs when we couldn't determine the source of the error.

func (InvalidFieldReferenceError) Error

type JSONRequest

type JSONRequest struct {
	Path    string
	Request BaseRequest
}

JSONRequest is the base request.

func (JSONRequest) EndpointPath

func (r JSONRequest) EndpointPath() string

EndpointPath returns with the path for the endpoint.

func (JSONRequest) ToBody

func (r JSONRequest) ToBody(token string) ([]byte, string, error)

ToBody returns with the JSON []byte representation of the request.

func (JSONRequest) Validate

func (r JSONRequest) Validate() error

Validate the request.

type MultipartRequest

type MultipartRequest struct {
	Path    string
	Request BaseRequest
}

MultipartRequest is the base multipart form request.

func (MultipartRequest) EndpointPath

func (r MultipartRequest) EndpointPath() string

EndpointPath returns with the path for the endpoint.

func (*MultipartRequest) ToBody

func (r *MultipartRequest) ToBody(token string) ([]byte, string, error)

ToBody generates the multipart request body.

func (MultipartRequest) Validate

func (r MultipartRequest) Validate() error

Validate the request.

type NotImplementedYet

type NotImplementedYet struct {
	Reason string
}

NotImplementedYet is an error for endpoint without implementation. The error will contain a reason for that, for example we don't know what is the response structure yet.

func (NotImplementedYet) Error

func (e NotImplementedYet) Error() string

type Request

type Request interface {
	ToBody(token string) (body []byte, contentType string, err error)
	EndpointPath() string
	Validate() error
}

Request is the interface that has to be implemented to be valid request.

type RequestError

type RequestError struct {
	Message string
	Origin  error
}

RequestError happens when something went wrong with the request.

func (RequestError) Error

func (e RequestError) Error() string

type RequestHandlerFunc

type RequestHandlerFunc func(Request, interface{}) error

RequestHandlerFunc is the function signature for request handlers called by services.

type RequestValidationError

type RequestValidationError struct {
	Request BaseRequest
	Message string
	Field   string
}

RequestValidationError occurs when one or more mandatory fields are missing.

func (RequestValidationError) Error

func (e RequestValidationError) Error() string

type String

type String *string

String is a simple string that can be nil.

func NewString

func NewString(value string) String

NewString transforms a string into a nillable string.

type UnknownError

type UnknownError struct {
	Response ErrorResponse
}

UnknownError occurs when we couldn't determine the source of the error.

func (UnknownError) Error

func (e UnknownError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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