ledger

package module
v0.0.0-...-f7ad73e Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: MIT Imports: 7 Imported by: 0

README

qledger-sdk-go

Go SDK for QLedger

Refer GoDoc for documentation.

Documentation

Index

Constants

View Source
const (
	// AccountsAPI is the endpoint for creating and updating accounts
	AccountsAPI = "/v1/accounts"
	// AccountsSearchAPI is the endpoint for searching accounts
	AccountsSearchAPI = "/v1/accounts/_search"
)
View Source
const (
	// TransactionsAPI is the endpoint for creating and updating transactions
	TransactionsAPI = "/v1/transactions"
	// TransactionsSearchAPI is the endpoint for searching transactions
	TransactionsSearchAPI = "/v1/transactions/_search"
)

Variables

View Source
var (
	ErrTransactionDuplicate = errors.New("Transaction is duplicate")
	ErrTransactionConflict  = errors.New("Transaction ID conflict")
	ErrTransactionInvalid   = errors.New("Transaction invalid")
	ErrTransactionNotfound  = errors.New("Transaction not found")

	ErrAccountConflict = errors.New("Account ID conflict")
	ErrAccountInvalid  = errors.New("Account invalid")
	ErrAccountNotfound = errors.New("Account not found")

	ErrInternalServer = errors.New("Ledger internal server error")
)

Functions

func NewUUID

func NewUUID() string

Types

type Account

type Account struct {
	ID      string                 `json:"id"`
	Balance int                    `json:"balance"`
	Data    map[string]interface{} `json:"data"`
}

Account holds information such as account ID, balance and search data

type Ledger

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

Ledger is the interface to all ledger API calls

func NewLedger

func NewLedger(endpoint string, authToken string) Ledger

NewLedger returns instance of a Ledger

func (*Ledger) CreateAccount

func (ledger *Ledger) CreateAccount(account *Account) error

CreateAccount creates a new account to QLedger

func (*Ledger) CreateTransaction

func (ledger *Ledger) CreateTransaction(transaction *Transaction) error

CreateTransaction makes a new transaction to QLedger

func (*Ledger) DoRequest

func (l *Ledger) DoRequest(method, url string, body io.Reader) (*http.Response, error)

DoRequest creates a new request to Ledger with necessary headers set

func (*Ledger) GetAccount

func (ledger *Ledger) GetAccount(accountID string) (*Account, error)

GetAccount returns an account in the Ledger which matches the given ID

func (*Ledger) GetEndpoint

func (l *Ledger) GetEndpoint() string

GetEndpoint returns the enpoint of the ledger

func (*Ledger) GetTransaction

func (ledger *Ledger) GetTransaction(txnID string) (*Transaction, error)

GetTransaction returns a transaction in the Ledger which matches the given ID

func (*Ledger) SearchAccounts

func (ledger *Ledger) SearchAccounts(searchQuery map[string]interface{}) ([]*Account, error)

SearchAccounts returns all account in the Ledger which satisfies the given search query

func (*Ledger) SearchTransactions

func (ledger *Ledger) SearchTransactions(searchQuery map[string]interface{}) ([]*Transaction, error)

SearchTransactions returns all transactions in the Ledger which satisfies the given search query

func (*Ledger) UpdateAccount

func (ledger *Ledger) UpdateAccount(account *Account) error

UpdateAccount creates a new account to QLedger

func (*Ledger) UpdateTransaction

func (ledger *Ledger) UpdateTransaction(txn *Transaction) error

UpdateTransaction updates `data` of existing transaction in QLedger

type Transaction

type Transaction struct {
	ID        string                 `json:"id"`
	Data      map[string]interface{} `json:"data"`
	Timestamp string                 `json:"timestamp"`
	Lines     []*TransactionLine     `json:"lines"`
}

Transaction holds information such as transaction ID, timestamp, movement of money between accounts and search data

type TransactionLine

type TransactionLine struct {
	AccountID string `json:"account"`
	Delta     int    `json:"delta"`
}

TransactionLine holds information about the account and amount transferred

Jump to

Keyboard shortcuts

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