Documentation ¶
Index ¶
- Constants
- Variables
- func CreateSimpleToken() string
- func DefaultEndpoint(c echo.Context) error
- func Duration(d time.Duration, dicimal int) time.Duration
- func ErrorResponse(c echo.Context, status int, err error, hint string) error
- func HandleFileUpload(ctx context.Context, req *http.Request, location, formName string) (string, error)
- func InitEndpoint(c echo.Context) error
- func LoginEndpoint(c echo.Context) error
- func LogoutEndpoint(c echo.Context) error
- func NewTransport(transport http.RoundTripper) *http.Client
- func ParseRange(r string) (int64, int64)
- func StandardResponse(c echo.Context, status int, res interface{}) error
- func WithAuthEndpoints(e *echo.Echo) *echo.Echo
- type Client
- func (c *Client) DELETE(uri string, request, response interface{}) (int, error)
- func (c *Client) GET(uri string, response interface{}) (int, error)
- func (c *Client) InitCommand(ds *settings.DialSettings) error
- func (c *Client) LoginCommand(token string) (*StatusObject, error)
- func (c *Client) LogoutCommand() error
- func (c *Client) POST(uri string, request, response interface{}) (int, error)
- func (c *Client) PUT(uri string, request, response interface{}) (int, error)
- type RelevantHeaders
- type StatusObject
Constants ¶
const ( // NamespacePrefix namespace for the client and CLI NamespacePrefix = "/a/v1" // format error messages MsgStatus = "%s. status: %d" )
const ( // auth routes InitRoute = "/auth" LoginRoute = "/auth/:sig/:token" LogoutRoute = "/auth/:sig" LoginExpiresAfter = 15 )
Variables ¶
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") )
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 ErrorResponse ¶
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 ¶
ParseRange extracts a byte range if specified. For specs see https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
func StandardResponse ¶
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) InitCommand ¶
func (c *Client) InitCommand(ds *settings.DialSettings) error
func (*Client) LoginCommand ¶
func (c *Client) LoginCommand(token string) (*StatusObject, error)
func (*Client) LogoutCommand ¶
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