handlers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package handlers provides HTTP handlers for different services across the application.

Index

Constants

View Source
const SyncQueryParameter = "sync"

Variables

View Source
var EmptyBodyError = &errors.RequestError{StatusCode: http.StatusBadRequest, Err: fmt.Errorf("empty body")}
View Source
var InvalidBodyError = &errors.RequestError{StatusCode: http.StatusBadRequest, Err: fmt.Errorf("invalid body")}

Functions

func Debug added in v0.9.0

func Debug(repoURL, sha1ver, buildtime string) http.Handler

func HandleHealthReady added in v0.9.0

func HandleHealthReady(w http.ResponseWriter, r *http.Request)

func IdempotencyHandler added in v0.9.0

func IdempotencyHandler(h http.Handler, opts IdempotencyHandlerOptions, store IdempotencyStore) http.Handler

IdempotencyHandler returns a http.HandlerFunc that checks for request idempotency when applicable

func Liveness added in v0.9.0

func Liveness(getLiveness func() (interface{}, error)) http.Handler

func UseCompress

func UseCompress(h http.Handler) http.Handler

func UseCors

func UseCors(h http.Handler) http.Handler

func UseIdempotency added in v0.9.0

func UseIdempotency(h http.Handler, opts IdempotencyHandlerOptions, store IdempotencyStore) http.Handler

func UseJson

func UseJson(h http.Handler) http.Handler

func UseLogging

func UseLogging(h http.Handler) http.Handler

Types

type Accounts

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

Accounts is a HTTP server for account management. It provides list, create and details APIs. It uses an account service to interface with data.

func NewAccounts

func NewAccounts(service accounts.Service) *Accounts

NewAccounts initiates a new accounts server.

func (*Accounts) AddNonCustodialAccount added in v0.7.0

func (s *Accounts) AddNonCustodialAccount() http.Handler

func (*Accounts) AddNonCustodialAccountFunc added in v0.7.0

func (s *Accounts) AddNonCustodialAccountFunc(rw http.ResponseWriter, r *http.Request)

func (*Accounts) Create

func (s *Accounts) Create() http.Handler

func (*Accounts) CreateFunc

func (s *Accounts) CreateFunc(rw http.ResponseWriter, r *http.Request)

Create creates a new account asynchronously. It returns a Job JSON representation.

func (*Accounts) DeleteNonCustodialAccount added in v0.7.0

func (s *Accounts) DeleteNonCustodialAccount() http.Handler

func (*Accounts) DeleteNonCustodialAccountFunc added in v0.7.0

func (s *Accounts) DeleteNonCustodialAccountFunc(rw http.ResponseWriter, r *http.Request)

func (*Accounts) Details

func (s *Accounts) Details() http.Handler

func (*Accounts) DetailsFunc

func (s *Accounts) DetailsFunc(rw http.ResponseWriter, r *http.Request)

Details returns details regarding an account. It reads the address for the wanted account from URL. Account service is responsible for validating the address.

func (*Accounts) List

func (s *Accounts) List() http.Handler

func (*Accounts) ListFunc

func (s *Accounts) ListFunc(rw http.ResponseWriter, r *http.Request)

List returns all accounts.

func (*Accounts) SyncAccountKeyCount added in v0.10.0

func (s *Accounts) SyncAccountKeyCount() http.Handler

func (*Accounts) SyncAccountKeyCountFunc added in v0.10.0

func (s *Accounts) SyncAccountKeyCountFunc(rw http.ResponseWriter, r *http.Request)

type IdempotencyHandlerOptions added in v0.9.0

type IdempotencyHandlerOptions struct {
	IgnorePaths []string
	Expiry      time.Duration
}

type IdempotencyStore added in v0.9.0

type IdempotencyStore interface {
	Get(key string) (bool, error)               // Get key by name, return bool "found" and possible error
	Set(key string, expiry time.Duration) error // Set key by name & expiry in seconds, return possible error
}

type IdempotencyStoreGorm added in v0.9.0

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

Gorm (SQL) store for idempotency keys

func NewIdempotencyStoreGorm added in v0.9.0

func NewIdempotencyStoreGorm(db *gorm.DB) *IdempotencyStoreGorm

func (*IdempotencyStoreGorm) Get added in v0.9.0

func (g *IdempotencyStoreGorm) Get(key string) (bool, error)

func (*IdempotencyStoreGorm) Prune added in v0.9.0

func (g *IdempotencyStoreGorm) Prune() error

Prune deletes all expired IdempotencyStoreGormItems from the database

func (*IdempotencyStoreGorm) Set added in v0.9.0

func (g *IdempotencyStoreGorm) Set(key string, expiry time.Duration) error

type IdempotencyStoreGormItem added in v0.9.0

type IdempotencyStoreGormItem struct {
	Key        string    `gorm:"column:key;primary_key"`
	ExpiryDate time.Time `gorm:"column:expiry_date"`
}

TODO: automatically expire/prune keys w/ ExpiryDate in the past

func (IdempotencyStoreGormItem) TableName added in v0.9.0

func (IdempotencyStoreGormItem) TableName() string

type IdempotencyStoreLocal added in v0.9.0

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

Local / in-memory store for idempotency keys, mainly for testing purposes

func NewIdempotencyStoreLocal added in v0.9.0

func NewIdempotencyStoreLocal() *IdempotencyStoreLocal

func (*IdempotencyStoreLocal) Get added in v0.9.0

func (m *IdempotencyStoreLocal) Get(key string) (bool, error)

func (*IdempotencyStoreLocal) Set added in v0.9.0

func (m *IdempotencyStoreLocal) Set(key string, expiry time.Duration) error

type IdempotencyStoreRedis added in v0.9.0

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

Redis store for idempotency keys

func NewIdempotencyStoreRedis added in v0.9.0

func NewIdempotencyStoreRedis(c redis.Conn) *IdempotencyStoreRedis

func (*IdempotencyStoreRedis) Get added in v0.9.0

func (r *IdempotencyStoreRedis) Get(key string) (bool, error)

func (*IdempotencyStoreRedis) Set added in v0.9.0

func (r *IdempotencyStoreRedis) Set(key string, expiry time.Duration) error

type IdempotencyStoreType added in v0.9.0

type IdempotencyStoreType int
const (
	IdempotencyStoreTypeLocal IdempotencyStoreType = iota
	IdempotencyStoreTypeShared
	IdempotencyStoreTypeRedis
)

func (IdempotencyStoreType) String added in v0.9.0

func (ist IdempotencyStoreType) String() string

type Jobs

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

Jobs is a HTTP server for jobs. It provides details API. It uses jobs service to interface with data.

func NewJobs

func NewJobs(service jobs.Service) *Jobs

NewJobs initiates a new jobs server.

func (*Jobs) Details

func (s *Jobs) Details() http.Handler

func (*Jobs) DetailsFunc

func (s *Jobs) DetailsFunc(rw http.ResponseWriter, r *http.Request)

Details returns details regarding a job. It reads the job id for the wanted job from URL. Job service is responsible for validating the job id.

func (*Jobs) List

func (s *Jobs) List() http.Handler

func (*Jobs) ListFunc

func (s *Jobs) ListFunc(rw http.ResponseWriter, r *http.Request)

List returns all jobs.

type Ops added in v0.11.0

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

Ops is a HTTP server for admin (system) operations.

func NewOps added in v0.11.0

func NewOps(service ops.Service) *Ops

NewOps initiates a new ops server.

func (*Ops) GetMissingFungibleVaults added in v0.11.0

func (s *Ops) GetMissingFungibleVaults() http.Handler

GetMissingFungibleVaults returns number of accounts that are missing a configured fungible token vault.

func (*Ops) GetMissingFungibleVaultsFunc added in v0.11.0

func (s *Ops) GetMissingFungibleVaultsFunc(rw http.ResponseWriter, r *http.Request)

GetMissingFungibleVaultsFunc returns number of accounts with missing fungible token vaults.

func (*Ops) InitMissingFungibleVaults added in v0.11.0

func (s *Ops) InitMissingFungibleVaults() http.Handler

InitMissingFungibleVaults starts the job to initialize missing fungible token vaults.

func (*Ops) InitMissingFungibleVaultsFunc added in v0.11.0

func (s *Ops) InitMissingFungibleVaultsFunc(rw http.ResponseWriter, r *http.Request)

InitMissingFungibleVaultsFunc starts job to init missing fungible token vaults.

type SyncKeyCountRequest added in v0.10.0

type SyncKeyCountRequest struct {
	Address flow.Address `json:"address"`
}

SyncKeyCountRequest represents a JSON payload for a HTTP request

type System added in v0.9.0

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

System is a HTTP server for system settings management.

func NewSystem added in v0.9.0

func NewSystem(service system.Service) *System

func (*System) GetSettings added in v0.9.0

func (s *System) GetSettings() http.Handler

func (*System) SetSettings added in v0.9.0

func (s *System) SetSettings() http.Handler

type Templates

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

Templates is a HTTP server for template management.

func NewTemplates

func NewTemplates(service templates.Service) *Templates

func (*Templates) AddToken

func (s *Templates) AddToken() http.Handler

func (*Templates) AddTokenFunc

func (s *Templates) AddTokenFunc(rw http.ResponseWriter, r *http.Request)

func (*Templates) GetToken

func (s *Templates) GetToken() http.Handler

func (*Templates) GetTokenFunc

func (s *Templates) GetTokenFunc(rw http.ResponseWriter, r *http.Request)

func (*Templates) ListTokens

func (s *Templates) ListTokens(tType templates.TokenType) http.Handler

func (*Templates) MakeListTokensFunc

func (s *Templates) MakeListTokensFunc(tType templates.TokenType) http.HandlerFunc

func (*Templates) RemoveToken

func (s *Templates) RemoveToken() http.Handler

func (*Templates) RemoveTokenFunc

func (s *Templates) RemoveTokenFunc(rw http.ResponseWriter, r *http.Request)

type Tokens

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

func NewTokens

func NewTokens(service tokens.Service) *Tokens

func (*Tokens) AccountTokens

func (s *Tokens) AccountTokens(tType templates.TokenType) http.Handler

func (*Tokens) CreateWithdrawal

func (s *Tokens) CreateWithdrawal() http.Handler

func (*Tokens) CreateWithdrawalFunc

func (s *Tokens) CreateWithdrawalFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) Details

func (s *Tokens) Details() http.Handler

func (*Tokens) DetailsFunc

func (s *Tokens) DetailsFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) GetDeposit

func (s *Tokens) GetDeposit() http.Handler

func (*Tokens) GetDepositFunc

func (s *Tokens) GetDepositFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) GetWithdrawal

func (s *Tokens) GetWithdrawal() http.Handler

func (*Tokens) GetWithdrawalFunc

func (s *Tokens) GetWithdrawalFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) ListDeposits

func (s *Tokens) ListDeposits() http.Handler

func (*Tokens) ListDepositsFunc

func (s *Tokens) ListDepositsFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) ListWithdrawals

func (s *Tokens) ListWithdrawals() http.Handler

func (*Tokens) ListWithdrawalsFunc

func (s *Tokens) ListWithdrawalsFunc(rw http.ResponseWriter, r *http.Request)

func (*Tokens) MakeAccountTokensFunc

func (s *Tokens) MakeAccountTokensFunc(tType templates.TokenType) http.HandlerFunc

func (*Tokens) Setup

func (s *Tokens) Setup() http.Handler

func (*Tokens) SetupFunc

func (s *Tokens) SetupFunc(rw http.ResponseWriter, r *http.Request)

type Transactions

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

func NewTransactions

func NewTransactions(service transactions.Service) *Transactions

NewTransactions initiates a new transactions server.

func (*Transactions) Create

func (s *Transactions) Create() http.Handler

func (*Transactions) CreateFunc

func (s *Transactions) CreateFunc(rw http.ResponseWriter, r *http.Request)

func (*Transactions) Details

func (s *Transactions) Details() http.Handler

func (*Transactions) DetailsFunc

func (s *Transactions) DetailsFunc(rw http.ResponseWriter, r *http.Request)

func (*Transactions) ExecuteScript

func (s *Transactions) ExecuteScript() http.Handler

func (*Transactions) ExecuteScriptFunc

func (s *Transactions) ExecuteScriptFunc(rw http.ResponseWriter, r *http.Request)

func (*Transactions) List

func (s *Transactions) List() http.Handler

func (*Transactions) ListFunc

func (s *Transactions) ListFunc(rw http.ResponseWriter, r *http.Request)

func (*Transactions) Sign added in v0.7.0

func (s *Transactions) Sign() http.Handler

func (*Transactions) SignFunc added in v0.7.0

func (s *Transactions) SignFunc(rw http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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