middleware

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxAddress contextKey

	CtxBlockDate
	CtxLimit
)

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 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 GetAddressCtx

func GetAddressCtx(r *http.Request) string

GetAddressCtx retrieves the ctxAddress 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

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

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. TODO: rename this function.

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

GetCountCtx retrieves the ctxOffset data ("from") from the request context. If not set, the return value is 0. TODO: rename this function.

func GetRawHexTx

func GetRawHexTx(r *http.Request) string

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 added in v3.1.0

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) string

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) []string

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 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 PostTxnsCtx

func PostTxnsCtx(next http.Handler) http.Handler

PostTxnsCtx extract transaction IDs from the POST body

func SearchPathCtx

func SearchPathCtx(next http.Handler) http.Handler

SearchPathCtx returns a http.HandlerFunc that embeds the value at the url part {search} into the request context (Still need this for the error page) TODO: make new error system

func StakeVersionLatestCtx

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

StakeVersionLatestCtx embeds the specified StakeVersionsLatest function into a request context.

func StatusCtx

func StatusCtx(r *http.Request, status apitypes.Status) context.Context

StatusCtx embeds the specified apitypes.Status 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 TicketPoolCtx added in v3.1.0

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() int
	GetBlockHeight(hash string) (int64, error)
	GetBlockHash(idx int64) (string, error)
}

type StakeVersionsLatest

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

Jump to

Keyboard shortcuts

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