api

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// NamespacePrefix namespace for the client and CLI
	NamespacePrefix = "/a/v1"

	// format error messages
	MsgStatus = "%s. status: %d"
)
View Source
const (
	// auth routes
	InitRoute   = "/auth"
	LoginRoute  = "/auth/:sig/:token"
	LogoutRoute = "/auth/:sig"

	LoginExpiresAfter = 15
)

Variables

View Source
var (
	// ErrInvalidRoute indicates that the route and/or its parameters are not valid
	ErrInvalidRoute = errors.New("invalid route")
	// ErrNotImplemented indicates that a function is not yet implemented
	ErrNotImplemented = errors.New("not implemented")
	// ErrInternalError indicates everything else
	ErrInternalError = errors.New("internal error")
)
View Source
var (
	// ErrMissingCredentials indicates that a credentials are is missing
	ErrMissingCredentials = errors.New("missing credentials")

	// ErrApiInvocationError indicates an error in an API call
	ErrApiInvocationError = errors.New("api invocation error")
)

Functions

func CreateSimpleToken

func CreateSimpleToken() string

func DefaultEndpoint

func DefaultEndpoint(c echo.Context) error

DefaultEndpoint just returns http.StatusOK

func Duration

func Duration(d time.Duration, dicimal int) time.Duration

func ErrorResponse

func ErrorResponse(c echo.Context, status int, err error, hint string) error

ErrorResponse reports the error and responds with an ErrorObject

func HandleFileUpload

func HandleFileUpload(ctx context.Context, req *http.Request, location, formName string) (string, error)

HandleFileUpload receives files from stores them locally

func InitEndpoint

func InitEndpoint(c echo.Context) error

func LoginEndpoint

func LoginEndpoint(c echo.Context) error

func LogoutEndpoint

func LogoutEndpoint(c echo.Context) error

func NewTransport

func NewTransport(transport http.RoundTripper) *http.Client

func ParseRange

func ParseRange(r string) (int64, int64)

ParseRange extracts a byte range if specified. For specs see https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

func StandardResponse

func StandardResponse(c echo.Context, status int, res interface{}) error

StandardResponse is the default way to respond to API requests

func WithAuthEndpoints

func WithAuthEndpoints(e *echo.Echo) *echo.Echo

Types

type Client

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

Client - API client encapsulating the http client

func NewClient

func NewClient(ds *settings.DialSettings) *Client

func (*Client) DELETE

func (c *Client) DELETE(uri string, request, response interface{}) (int, error)

func (*Client) GET

func (c *Client) GET(uri string, response interface{}) (int, error)

GET is used to request data from the API. No payload, only queries!

func (*Client) InitCommand

func (c *Client) InitCommand(ds *settings.DialSettings) error

func (*Client) LoginCommand

func (c *Client) LoginCommand(token string) (*StatusObject, error)

func (*Client) LogoutCommand

func (c *Client) LogoutCommand() error

func (*Client) POST

func (c *Client) POST(uri string, request, response interface{}) (int, error)

func (*Client) PUT

func (c *Client) PUT(uri string, request, response interface{}) (int, error)

type RelevantHeaders

type RelevantHeaders struct {
	Range           string `header:"Range"`
	UserAgent       string `header:"User-Agent"`
	Forwarded       string `header:"Forwarded"`
	XForwardedFor   string `header:"X-Forwarded-For"`
	XForwwardedHost string `header:"X-Forwarded-Host"`
	Referer         string `header:"Referer"`
}

RelevantHeaders represents the most important headers

func ExtractHeaders

func ExtractHeaders(r *http.Request) RelevantHeaders

ExtractHeaders extracts the relevant HTTP header stuff only

func (*RelevantHeaders) Ranges

func (h *RelevantHeaders) Ranges() (int64, int64)

type StatusObject

type StatusObject struct {
	Status    int    `json:"status" binding:"required"`
	Message   string `json:"message" binding:"required"`
	RootError error  `json:"-"`
}

StatusObject is used to report operation status and errors in an API request. The struct can be used as a response object or be treated as an error object

func NewErrorStatus

func NewErrorStatus(s int, e error, hint string) StatusObject

NewErrorStatus initializes a new StatusObject from an error

func NewStatus

func NewStatus(s int, m string) StatusObject

NewStatus initializes a new StatusObject

func (*StatusObject) Error

func (so *StatusObject) Error() string

func (*StatusObject) String

func (so *StatusObject) String() string

Jump to

Keyboard shortcuts

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