query

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGet            = "get"
	MethodFileList       = "file_list"
	MethodAccountList    = "account_list"
	MethodStatus         = "status"
	MethodResolve        = "resolve"
	MethodClaimSearch    = "claim_search"
	MethodPurchaseCreate = "purchase_create"
	MethodWalletBalance  = "wallet_balance"
	MethodWalletSend     = "wallet_send"
	MethodSyncApply      = "sync_apply"

	ParamStreamingUrl    = "streaming_url"
	ParamPurchaseReceipt = "purchase_receipt"
)
View Source
const (

	// AllMethodsHook is used as the first argument to Add*Hook to make it apply to all methods
	AllMethodsHook = ""
)

Variables

This section is empty.

Functions

func MethodAcceptsWallet

func MethodAcceptsWallet(method string) bool

MethodAcceptsWallet returns true for methods that can accept wallet_id

func MethodRequiresWallet

func MethodRequiresWallet(method string) bool

MethodRequiresWallet returns true for methods that require wallet_id

Types

type Caller

type Caller struct {
	// Preprocessor is applied to query before it's sent to the SDK.
	Preprocessor func(q *Query)

	// Cache stores cachable queries to improve performance
	Cache cache.QueryCache
	// contains filtered or unexported fields
}

Caller patches through JSON-RPC requests from clients, doing pre/post-processing, account processing and validation.

func NewCaller

func NewCaller(endpoint string, userID int) *Caller

func (*Caller) AddPostflightHook added in v0.14.4

func (c *Caller) AddPostflightHook(method string, hf Hook, name string)

AddPostflightHook adds query postflight hook function, allowing to amend the response before it gets sent back to the client or to modify log entry fields.

func (*Caller) AddPreflightHook added in v0.14.1

func (c *Caller) AddPreflightHook(method string, hf Hook, name string)

AddPreflightHook adds query preflight hook function, allowing to amend the query before it gets sent to the JSON-RPC server, with an option to return an early response, avoiding sending the query to JSON-RPC server altogether.

func (*Caller) Call

func (c *Caller) Call(req *jsonrpc.RPCRequest) (*jsonrpc.RPCResponse, error)

Call method forwards a JSON-RPC request to the lbrynet server. It returns a response that is ready to be sent back to the JSON-RPC client as is.

func (*Caller) CloneWithoutHook added in v0.14.4

func (c *Caller) CloneWithoutHook(method string, name string) *Caller

type Hook added in v0.14.1

type Hook func(c *Caller, hctx *HookContext) (*jsonrpc.RPCResponse, error)

Hook is a function that can be applied to certain methods during preflight or postflight phase using context data about the client query being performed. Hooks can modify both query and response, as well as perform additional queries via supplied Caller. If nil is returned instead of *jsonrpc.RPCResponse, original response is returned.

type HookContext added in v0.14.4

type HookContext struct {
	Query    *Query
	Response *jsonrpc.RPCResponse
	// contains filtered or unexported fields
}

HookContext contains data about the query being performed. When supplied in the postflight stage, it will contain Response and LogEntry, otherwise those will be nil.

func (*HookContext) AddLogField added in v0.14.4

func (hc *HookContext) AddLogField(key string, value interface{})

AddLogField injects additional data into default post-query log entry

type Query

type Query struct {
	Request  *jsonrpc.RPCRequest
	WalletID string
}

Query is a wrapper around client JSON-RPC query for easier (un)marshaling and processing.

func NewQuery

func NewQuery(req *jsonrpc.RPCRequest, walletID string) (*Query, error)

NewQuery initializes Query object with JSON-RPC request supplied as bytes. The object is immediately usable and returns an error in case request parsing fails. If wallet_id is not empty, it will be added as a param to the query when the Caller calls it.

func (*Query) IsAuthenticated added in v0.14.4

func (q *Query) IsAuthenticated() bool

IsAuthenticated returns true if query is performed by an authenticated user

func (*Query) Method

func (q *Query) Method() string

Method is a shortcut for query method.

func (*Query) Params

func (q *Query) Params() interface{}

Params is a shortcut for query params.

func (*Query) ParamsAsMap

func (q *Query) ParamsAsMap() map[string]interface{}

ParamsAsMap returns query params converted to plain map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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