Documentation ¶
Index ¶
- Constants
- type ArticleClient
- func (s *ArticleClient) Create(article *schema.ArticleCreateRequest) (*schema.Article, *Response, error)
- func (s *ArticleClient) Deactivate(id int) (*schema.Article, *Response, error)
- func (s *ArticleClient) Get(id int) (*schema.Article, *Response, error)
- func (s *ArticleClient) List(opt *ListOpts) ([]schema.Article, *Response, error)
- func (s *ArticleClient) SearchByBarcode(barcode string, opt *ListOpts) ([]schema.Article, *Response, error)
- func (s *ArticleClient) SearchByName(name string, opt *ListOpts) ([]schema.Article, *Response, error)
- func (s *ArticleClient) Update(id int, article *schema.ArticleUpdateRequest) (*schema.Article, *Response, error)
- type Client
- type ClientOption
- type ListOpts
- type MetricsClient
- type Response
- type SettingsClient
- type TransactionClient
- type TransactionContext
- func (c *TransactionContext) Create(trc *schema.TransactionCreateRequest) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) Delta(amount int) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) Get(id int) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) List(opt *ListOpts) ([]schema.Transaction, *Response, error)
- func (c *TransactionContext) Purchase(article int, count int) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) Revert(id int) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) TransferFunds(recipient int, amount int) (*schema.Transaction, *Response, error)
- func (c *TransactionContext) WithComment(comment string) *TransactionContext
- type UserClient
- func (c *UserClient) Create(user *schema.UserCreateRequest) (*schema.User, *Response, error)
- func (c *UserClient) Deactivate(id int) (*schema.User, *Response, error)
- func (c *UserClient) Get(id int) (*schema.User, *Response, error)
- func (c *UserClient) GetByName(name string) (*schema.User, *Response, error)
- func (c *UserClient) List(opt *ListOpts) ([]schema.User, *Response, error)
- func (c *UserClient) Search(query string, opt *ListOpts) ([]schema.User, *Response, error)
- func (c *UserClient) Update(id int, user *schema.UserUpdateRequest) (*schema.User, *Response, error)
Constants ¶
const ( LibName = "go-strichliste" LibVersion = "0.3.0" ApiVersion = "2:1.6.1" // compatible with this Strichliste API version DefaultEndpoint = "https://demo.strichliste.org/api" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArticleClient ¶
type ArticleClient struct {
// contains filtered or unexported fields
}
An ArticleClient carries the necessary context to interact with the /article endpoint
func (*ArticleClient) Create ¶
func (s *ArticleClient) Create(article *schema.ArticleCreateRequest) (*schema.Article, *Response, error)
POST /article
- ErrorParameterMissing
- ErrorParameterInvalid
Creates a new article and returns it.
func (*ArticleClient) Deactivate ¶
DELETE /article/{articleId}
- ErrorArticleNotFound
Deactivates an article by ID; returns the deactivated article. Note that actual deletion is not possible.
func (*ArticleClient) List ¶
GET /article
Retrieves a list of articles (both active and inactive). Pagination is possible via ListOpts, which can be nil.
func (*ArticleClient) SearchByBarcode ¶
func (s *ArticleClient) SearchByBarcode(barcode string, opt *ListOpts) ([]schema.Article, *Response, error)
GET /article/search
Retrieves a list of articles whose barcodes match, or include, the passed barcode. Pagination is possible via ListOpts, which can be nil.
func (*ArticleClient) SearchByName ¶
func (s *ArticleClient) SearchByName(name string, opt *ListOpts) ([]schema.Article, *Response, error)
GET /article/search
Retrieves a list of articles whose names match, or include, the passed name. Pagination is possible via ListOpts, which can be nil.
func (*ArticleClient) Update ¶
func (s *ArticleClient) Update(id int, article *schema.ArticleUpdateRequest) (*schema.Article, *Response, error)
POST /article/{articleId}
- ErrorArticleNotFound
- ErrorParameterMissing
- ErrorParameterInvalid
Updates an article by ID. Note that this operation checks for referential integrity and may not update the article, but instead create a new one, referencing and deactivating the old version. The returned article is always new version — either replaced or updated.
type Client ¶
type Client struct { User UserClient Transaction TransactionClient Article ArticleClient Settings SettingsClient Metrics MetricsClient // contains filtered or unexported fields }
Contains the necessary context to make API requests.
func NewClient ¶
func NewClient(options ...ClientOption) *Client
Create a new API client. This is the library's entrypoint.
type ClientOption ¶
type ClientOption func(*Client)
func WithApplication ¶
func WithApplication(name, version string) ClientOption
Configure the application's name and version to use when contacting the API endpoint. The User Agent for requests derives from this value. Not setting this option will default to LibName and LibVersion.
func WithEndpoint ¶
func WithEndpoint(endpoint string) ClientOption
Configure the URL of the API endpoint. Not setting this option will default to DefaultEndpoint.
type ListOpts ¶
type ListOpts struct { Page uint // page number (1-indexed, 0 means all on one page) PerPage uint // items per page (0 means default size) }
Allows for result pagination and result limitation.
Pagination works by passing a page number and the number of items on each page.
Limiting results works by keeping Page at 0 and setting PerPage to the desired number of total entries.
Note that endpoint semantics differ; some use "most recent items" and some "oldest items". TODO document this behaviour.
type MetricsClient ¶
type MetricsClient struct {
// contains filtered or unexported fields
}
A MetricsClient carries the necessary context to interact with the /metrics endpoint
func (*MetricsClient) ForSystem ¶
func (s *MetricsClient) ForSystem() (*schema.SystemMetrics, *Response, error)
GET /metrics
Retrieves the current server metrics.
func (*MetricsClient) ForUser ¶
func (s *MetricsClient) ForUser(id int) (*schema.UserMetrics, *Response, error)
GET /user/{userId}/metrics
Retrieves the current user metrics by user ID.
type SettingsClient ¶
type SettingsClient struct {
// contains filtered or unexported fields
}
A SettingsClient carries the necessary context to interact with the /settings endpoint
type TransactionClient ¶
type TransactionClient struct {
// contains filtered or unexported fields
}
An ArticleClient carries the necessary context to interact with the /transaction endpoint.
func (*TransactionClient) Context ¶
func (c *TransactionClient) Context(user int) *TransactionContext
Create a user-specific context by user ID, which allows issuing transactions as that user.
func (*TransactionClient) List ¶
func (c *TransactionClient) List(opt *ListOpts) ([]schema.Transaction, *Response, error)
GET /transaction
Retrieves a list of recent transactions. Pagination is possible via ListOpts, which can be nil.
type TransactionContext ¶
type TransactionContext struct { TransactionClient // contains filtered or unexported fields }
TransactionContext extends the TransactionClient with additional user-specific context.
func (*TransactionContext) Create ¶
func (c *TransactionContext) Create(trc *schema.TransactionCreateRequest) (*schema.Transaction, *Response, error)
POST /user/{userId}/transaction
- ErrorUserNotFound
- ErrorParameterMissing
- ErrorParameterInvalid
- ErrorAccountBalanceBoundary
- ErrorTransactionBoundary
- TODO ErrorArticleNotFound?
Creates a raw transaction and returns it. Consider using these wrappers for specific use-cases:
- Delta
- Purchase
- TransferFunds
func (*TransactionContext) Delta ¶
func (c *TransactionContext) Delta(amount int) (*schema.Transaction, *Response, error)
Utility wrapper for Create; see Create for possible errors. Deposit or withdraw funds for the current User; returns the created transaction.
func (*TransactionContext) Get ¶
func (c *TransactionContext) Get(id int) (*schema.Transaction, *Response, error)
GET /user/{userId}/transaction/{txId}
- ErrorUserNotFound
- ErrorTransactionNotFound
Retrieves a transaction by ID.
func (*TransactionContext) List ¶
func (c *TransactionContext) List(opt *ListOpts) ([]schema.Transaction, *Response, error)
GET /user/{userId}/transaction
- ErrorUserNotFound
Retrieves a list of transactions issued by this user. Pagination is possible via ListOpts, which can be nil.
func (*TransactionContext) Purchase ¶
func (c *TransactionContext) Purchase(article int, count int) (*schema.Transaction, *Response, error)
Utility wrapper for Create; see Create for possible errors. Purchase a number of articles by ID with the current user; returns the created transaction.
func (*TransactionContext) Revert ¶
func (c *TransactionContext) Revert(id int) (*schema.Transaction, *Response, error)
DELETE /user/{userId}/transaction
- ErrorUserNotFound
- ErrorTransactionNotFound
- ErrorTransactionNotDeletable
Revert a transaction by ID; returns the reversed transaction. Not all transactions are reversible; check Transaction.IsReversible. Note that actual deletion is not possible.
func (*TransactionContext) TransferFunds ¶
func (c *TransactionContext) TransferFunds(recipient int, amount int) (*schema.Transaction, *Response, error)
Utility wrapper for Create; see Create for possible errors. Transfer an amount of funds from the current user to another by ID; returns the created transaction.
func (*TransactionContext) WithComment ¶
func (c *TransactionContext) WithComment(comment string) *TransactionContext
Set the comment to use for all new transactions that use the returned context.
type UserClient ¶
type UserClient struct {
// contains filtered or unexported fields
}
A UserClient carries the necessary context to interact with the /user endpoint
func (*UserClient) Create ¶
func (c *UserClient) Create(user *schema.UserCreateRequest) (*schema.User, *Response, error)
POST /user
- ErrorUserAlreadyExists
Creates a new user and returns it.
func (*UserClient) Deactivate ¶
Deactivates a user by ID; returns the deactivated user. Note that actual deletion is not possible.
func (*UserClient) List ¶
GET /user
Retrieves the list of users (both active and inactive). Pagination is possible via ListOpts, which can be nil.
func (*UserClient) Search ¶
GET /user/search
Retrieves a list of users whose names match, or include, the passed name. Pagination is possible via ListOpts, which can be nil.
func (*UserClient) Update ¶
func (c *UserClient) Update(id int, user *schema.UserUpdateRequest) (*schema.User, *Response, error)
POST /user/{userId}
- ErrorUserNotFound
- ErrorUserAlreadyExists
- ErrorParameterMissing
- ErrorParameterInvalid
Updates a user by ID and returns it.