vctr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 0

README

go-wrapper

An API wrapper for the vctr API gateway written in Go.

Documentation

Overview

Package vctr provides a simple to use API wrapper for the vctr REST API.

Index

Constants

View Source
const Version = "1.0.0"

The current package version.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKeyCreatedModel

type ApiKeyCreatedModel struct {
	*ApiKeyModel

	Key string `json:"key"`
}

type ApiKeyModel

type ApiKeyModel struct {
	*EntityModel

	LastAccess  Time `json:"last_access"`
	AccessCount int  `json:"access_count"`
}

type Client

type Client struct {
	// Authorization endpoints.
	Auth *authClient
	// Users endpoints.
	Users *userClient
	// Links endpoints.
	Links *linksClient
	// API Key endpoints.
	ApiKey *apikeyClient
	// contains filtered or unexported fields
}

Client provides a simple interface to access the vctr REST API gateway.

func NewClient

func NewClient(endpoint string, authHeader ...string) (c *Client)

NewClient creates a new client instance connecting to the passed vctr instance endpoint, for example https://s.zekro.de or https://vctr.yourhost.com.

You can also pass optional authorization header tokens which can be used to authenticate against the API, but it is recommented to use the methods NewClientWithApiToken and NewClientWithSessionToken for that purpose.

func NewClientWithApiToken

func NewClientWithApiToken(endpoint, token string) (c *Client)

NewClientWithApiKey is shorthand for NewClient with an initial API key used to authenticate against the API.

func NewClientWithSessionToken

func NewClientWithSessionToken(endpoint, token string) (c *Client)

NewClientWithSessionKey is shorthand for NewClient with an initial session key used to authenticate against the API.

func (*Client) SetApiToken

func (c *Client) SetApiToken(token string)

SetApiToken sets the passed API token to the client so that it will be used in subsequent requests to authenticate against the API.

func (*Client) SetSessionToken

func (c *Client) SetSessionToken(token string)

SetSessionToken sets the passed session token to the client so that it will be used in subsequent requests to authenticate against the API.

type CountModel

type CountModel struct {
	Count int `json:"count"`
}

type EntityModel

type EntityModel struct {
	Guid    string `json:"guid"`
	Created Time   `json:"created"`
	// contains filtered or unexported fields
}

type LinkCreateModel

type LinkCreateModel struct {
	Ident             string `json:"ident"`
	Destination       string `json:"destination"`
	Enabled           bool   `json:"enabled"`
	PermanentRedirect bool   `json:"permanent_redirect"`
	TotalAccessLimit  int    `json:"total_access_limit"`
	Expires           Time   `json:"expires"`
	Password          string `json:"password"`
}

type LinkModel

type LinkModel struct {
	*EntityModel

	Ident             string `json:"ident"`
	Destination       string `json:"destination"`
	Enabled           bool   `json:"enabled"`
	PermanentRedirect bool   `json:"permanent_redirect"`
	PasswordRequired  bool   `json:"password_required"`
	LastAccess        Time   `json:"last_access"`
	AccessCount       int    `json:"access_count"`
	UniqueAccessCount int    `json:"unique_access_count"`
	TotalAccessLimit  int    `json:"total_access_limit"`
	Expires           Time   `json:"expires"`

	Creator *UserModel `json:"creator"`
}

type LoginModel

type LoginModel struct {
	Ident    string `json:"ident"`
	Password string `json:"password"`
	Remember bool   `json:"remember"`
}

type Permissions

type Permissions int
const (
	PermViewLinks Permissions = 1 << (iota + 1)
	PermCreateLinks
	PermUpdateLinks
	PermDeleteLinks
	PermViewUsers
	PermCreateUsers
	PermUpdateUsers
	PermDeleteUsers
	PermPerformStateChanges
	PermCreateApiKey

	PermUnset Permissions = -1
	PermAdmin Permissions = 2147483647
)

type ResponseError

type ResponseError struct {
	Code    int
	Message string
}

ResponseError wraps a HTTP response error with error response code and an API error message.

ResponseError implements the error interface.

func (*ResponseError) Error

func (r *ResponseError) Error() string

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(buf []byte) (err error)

type UserCreateModel

type UserCreateModel struct {
	UserName    string      `json:"username"`
	Password    string      `json:"password"`
	Permissions Permissions `json:"permissions"`
}

type UserLoginModel

type UserLoginModel struct {
	*UserModel

	SessionKey string `json:"session_key"`
}

type UserModel

type UserModel struct {
	*EntityModel

	UserName    string      `json:"username"`
	Permissions Permissions `json:"permissions"`
	LastLogin   Time        `json:"last_login"`
}
func (u *UserModel) Links(limit, offset int) (res []*LinkModel, err error)

Links returns a list io links of the current user entity.

limit defines the maximum ammount of response entities and offset defines the number of entities to be skipped.

func (*UserModel) LinksCount

func (u *UserModel) LinksCount() (res *CountModel, err error)

LinksCount returns the number of links owned by the current user entity.

func (u *UserModel) SearchLinks(query string, limit, offset int) (res []*LinkModel, err error)

SearchLinks searches the links of the current user by the given query.

limit defines the maximum ammount of response entities and offset defines the number of entities to be skipped.

type UserUpdateModel

type UserUpdateModel struct {
	UserName    string      `json:"username"`
	Password    string      `json:"password"`
	Permissions Permissions `json:"permissions"`
}

type UserUpdateSelfModel

type UserUpdateSelfModel struct {
	UserName        string `json:"username"`
	CurrentPassword string `json:"current_password"`
	NewPassword     string `json:"new_password"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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