middleware

package module
v3.0.0-...-c90cce5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: ISC Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxAddress contextKey

	CtxBlockDate
	CtxLimit
)

These are the keys for different types of values stored in a request context.

Variables

This section is empty.

Functions

func APIDirectory

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

APIDirectory is the actual handler used with apiDocs (e.g. mux.With(apiDocs(mux)).HandleFunc("/help", APIDirectory))

func AddressPathCtx

func AddressPathCtx(next http.Handler) http.Handler

AddressPathCtx returns a http.HandlerFunc that embeds the value at the url part {address} into the request context.

func AddressPostCtx

func AddressPostCtx(next http.Handler) http.Handler

AddressPostCtx returns a http.HandlerFunc that embeds the {addrs} value in the post request into the request context.

func AgendIdCtx

func AgendIdCtx(next http.Handler) http.Handler

AgendIdCtx returns a http.HandlerFunc that embeds the value at the url part {agendaId} into the request context. This is here for backward compatibility.

func AgendaIdCtx

func AgendaIdCtx(next http.Handler) http.Handler

AgendaIdCtx returns a http.HandlerFunc that embeds the value at the url part {agendaId} into the request context.

func BlockDateQueryCtx

func BlockDateQueryCtx(next http.Handler) http.Handler

BlockDateQueryCtx returns a http.Handlerfunc that embeds the {blockdate, limit} value in the request into the request context.

func BlockHashLatestCtx

func BlockHashLatestCtx(r *http.Request, source DataSource) context.Context

BlockHashLatestCtx embeds the current block height and hash into a request context.

func BlockHashPathAndIndexCtx

func BlockHashPathAndIndexCtx(r *http.Request, source DataSource) context.Context

BlockHashPathAndIndexCtx embeds the value at the url part {blockhash}, and the corresponding block index, into a request context.

func BlockHashPathCtx

func BlockHashPathCtx(next http.Handler) http.Handler

BlockHashPathCtx returns a http.HandlerFunc that embeds the value at the url part {blockhash} into the request context.

func BlockIndex0PathCtx

func BlockIndex0PathCtx(next http.Handler) http.Handler

BlockIndex0PathCtx returns a http.HandlerFunc that embeds the value at the url part {idx0} into the request context.

func BlockIndexLatestCtx

func BlockIndexLatestCtx(r *http.Request, source DataSource) context.Context

BlockIndexLatestCtx embeds the current block height into a request context.

func BlockIndexOrHashPathCtx

func BlockIndexOrHashPathCtx(next http.Handler) http.Handler

BlockIndexOrHashPathCtx returns a http.HandlerFunc that embeds the value at the url part {idxorhash} into the request context.

func BlockIndexPathCtx

func BlockIndexPathCtx(next http.Handler) http.Handler

BlockIndexPathCtx returns a http.HandlerFunc that embeds the value at the url part {idx} into the request context.

func BlockStepPathCtx

func BlockStepPathCtx(next http.Handler) http.Handler

BlockStepPathCtx returns a http.HandlerFunc that embeds the value at the url part {step} into the request context.

func CacheControl

func CacheControl(maxAge int64) func(http.Handler) http.Handler

CacheControl creates a new middleware to set the HTTP response header with "Cache-Control: max-age=maxAge" where maxAge is in seconds.

func ChartGroupingCtx

func ChartGroupingCtx(next http.Handler) http.Handler

ChartGroupingCtx returns a http.HandlerFunc that embeds the value art the url part {chartgrouping} into the request context.

func ChartTypeCtx

func ChartTypeCtx(next http.Handler) http.Handler

ChartTypeCtx returns a http.HandlerFunc that embeds the value at the url part {charttype} into the request context.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func ExchangeTokenContext

func ExchangeTokenContext(next http.Handler) http.Handler

ExchangeTokenContext pulls the exchange token from the URL.

func GetAddressCtx

func GetAddressCtx(r *http.Request, activeNetParams *chaincfg.Params, maxAddrs int) ([]string, error)

GetAddressCtx retrieves the CtxAddress data from the request context. If not set, the return value is an empty string. The CtxAddress string data may be a comma-separated list of addresses, subject to the provided maximum number of addresses allowed. Duplicate addresses are removed, but the limit is enforced prior to removal of duplicates.

func GetAgendaIdCtx

func GetAgendaIdCtx(r *http.Request) string

GetAgendaIdCtx retrieves the ctxAgendaId data from the request context. If not set, the return value is an empty string.

func GetBlockDateCtx

func GetBlockDateCtx(r *http.Request) string

GetBlockDateCtx retrieves the ctxBlockDate data from the request context. If not set, the return value is an empty string.

func GetBlockHashCtx

func GetBlockHashCtx(r *http.Request) (string, error)

GetBlockHashCtx retrieves the ctxBlockHash data from the request context. If not set, the return value is an empty string.

func GetBlockHeightCtx

func GetBlockHeightCtx(r *http.Request, source DataSource) (int64, error)

GetBlockHeightCtx returns the block height for the block index or hash specified on the URL path.

func GetBlockIndex0Ctx

func GetBlockIndex0Ctx(r *http.Request) int

GetBlockIndex0Ctx retrieves the ctxBlockIndex0 data from the request context. If not set, the return value is -1.

func GetBlockIndexCtx

func GetBlockIndexCtx(r *http.Request) int

GetBlockIndexCtx retrieves the ctxBlockIndex data from the request context. If not set, the return -1.

func GetBlockStepCtx

func GetBlockStepCtx(r *http.Request) int

GetBlockStepCtx retrieves the ctxBlockStep data from the request context. If not set, the return value is -1.

func GetChartGroupingCtx

func GetChartGroupingCtx(r *http.Request) string

GetChartGroupingCtx retrieves the ctxChart data from the request context. If not set, the return value is an empty string.

func GetChartTypeCtx

func GetChartTypeCtx(r *http.Request) string

GetChartTypeCtx retrieves the ctxChart data from the request context. If not set, the return value is an empty string.

func GetCountCtx

func GetCountCtx(r *http.Request) int

GetCountCtx retrieves the ctxCount data ("to") URL path element from the request context. If not set, the return value is 20.

func GetLatestVoteVersionCtx

func GetLatestVoteVersionCtx(r *http.Request) int

GetLatestVoteVersionCtx attempts to retrieve the latest stake version embedded in the request context.

func GetMCtx

func GetMCtx(r *http.Request) int

GetMCtx retrieves the ctxM data from the request context. If not set, the return value is -1.

func GetNCtx

func GetNCtx(r *http.Request) int

GetNCtx retrieves the ctxN data from the request context. If not set, the return value is -1.

func GetOffsetCtx

func GetOffsetCtx(r *http.Request) int

GetOffsetCtx retrieves the ctxOffset data ("from") from the request context. If not set, the return value is 0.

func GetPageNumCtx

func GetPageNumCtx(r *http.Request) int

GetPageNumCtx retrieves the ctxPageNum data ("pageNum") URL path element from the request context. If not set, the return value is 1. The page number must be a postitive integer.

func GetProposalTokenCtx

func GetProposalTokenCtx(r *http.Request) string

GetProposalTokenCtx retrieves the ctxProposalToken data from the request context. If the value is not set, an empty string is returned.

func GetRawHexTx

func GetRawHexTx(r *http.Request) (string, error)

GetRawHexTx retrieves the ctxRawHexTx data from the request context. If not set, the return value is an empty string.

func GetStatusInfoCtx

func GetStatusInfoCtx(r *http.Request) string

GetStatusInfoCtx retrieves the ctxGetStatus data ("q" POST form data) from the request context. If not set, the return value is an empty string.

func GetTpCtx

func GetTpCtx(r *http.Request) string

GetTpCtx retrieves the ctxTp data from the request context. If the value is not set, an empty string is returned.

func GetTxIDCtx

func GetTxIDCtx(r *http.Request) (*chainhash.Hash, error)

GetTxIDCtx retrieves the ctxTxHash data from the request context. If not set, the return value is an empty string.

func GetTxIOIndexCtx

func GetTxIOIndexCtx(r *http.Request) int

GetTxIOIndexCtx retrieves the ctxTxInOutIndex data from the request context. If not set, the return value is -1.

func GetTxnsCtx

func GetTxnsCtx(r *http.Request) ([]*chainhash.Hash, error)

GetTxnsCtx retrieves the ctxTxns data from the request context. If not set, the return value is an empty string slice.

func MPathCtx

func MPathCtx(next http.Handler) http.Handler

MPathCtx returns a http.HandlerFunc that embeds the value at the url part {M} into the request context

func NPathCtx

func NPathCtx(next http.Handler) http.Handler

NPathCtx returns a http.HandlerFunc that embeds the value at the url part {N} into the request context.

func Next

func Next(next http.Handler) http.Handler

Next is a dummy middleware that just continues with the next http.Handler.

func OriginalRequestURI

func OriginalRequestURI(next http.Handler) http.Handler

OriginalRequestURI checks the X-Original-Request-URI HTTP request header for a valid URI, and patches the request URL's Path and RawPath. This may be useful in the event that a reverse proxy maps requests on path A to path B, but the request handler requires the original path A (e.g. generating links relative to path A).

func PageNumCtx

func PageNumCtx(next http.Handler) http.Handler

PageNumCtx returns a http.Handlerfunc that embeds the {pageNum} URL query parameter value in the request into the request context.

func PaginationCtx

func PaginationCtx(next http.Handler) http.Handler

PaginationCtx returns a http.Handlerfunc that embeds the {to,from} value in the request into the request context.

func PostBroadcastTxCtx

func PostBroadcastTxCtx(next http.Handler) http.Handler

PostBroadcastTxCtx is middleware that checks for parameters given in POST request body of the broadcast transaction endpoint.

func PostTxnsCtx

func PostTxnsCtx(next http.Handler) http.Handler

PostTxnsCtx extract transaction IDs from the POST body

func ProposalTokenCtx

func ProposalTokenCtx(next http.Handler) http.Handler

ProposalTokenCtx returns a http.HandlerFunc that embeds the value at the url part {token} into the request context

func RetrieveExchangeTokenCtx

func RetrieveExchangeTokenCtx(r *http.Request) string

RetrieveExchangeTokenCtx tries to fetch the exchange token from the request context.

func RetrieveStickWidthCtx

func RetrieveStickWidthCtx(r *http.Request) string

RetrieveStickWidthCtx tries to fetch the candlestick width from the request context.

func StakeVersionLatestCtx

func StakeVersionLatestCtx(r *http.Request, stakeVerFun StakeVersionsLatest) context.Context

StakeVersionLatestCtx embeds the specified StakeVersionsLatest function into a request context.

func StatusInfoCtx

func StatusInfoCtx(r *http.Request, source DataSource) context.Context

StatusInfoCtx embeds the best block index and the POST form data for parameter "q" into a request context.

func StickWidthContext

func StickWidthContext(next http.Handler) http.Handler

ExchangeTokenContext pulls the bin width from the URL.

func TicketPoolCtx

func TicketPoolCtx(next http.Handler) http.Handler

TicketPoolCtx returns a http.HandlerFunc that embeds the value at the url part {tp} into the request context

func TransactionHashCtx

func TransactionHashCtx(next http.Handler) http.Handler

TransactionHashCtx returns a http.HandlerFunc that embeds the value at the url part {txid} into the request context.

func TransactionIOIndexCtx

func TransactionIOIndexCtx(next http.Handler) http.Handler

TransactionIOIndexCtx returns a http.HandlerFunc that embeds the value at the url part {txinoutindex} into the request context

func TransactionsCtx

func TransactionsCtx(next http.Handler) http.Handler

TransactionsCtx returns a http.Handlerfunc that embeds the {address, blockhash} value in the request into the request context.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

func ValidateTxnsPostCtx

func ValidateTxnsPostCtx(next http.Handler) http.Handler

ValidateTxnsPostCtx will confirm Post content length is valid.

Types

type DataSource

type DataSource interface {
	GetHeight() (int64, error)
	GetBlockHeight(hash string) (int64, error)
	GetBlockHash(idx int64) (string, error)
}

type StakeVersionsLatest

type StakeVersionsLatest func() (*chainjson.StakeVersions, error)

Jump to

Keyboard shortcuts

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