middleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainMiddleware

func ChainMiddleware(handler http.Handler, middlewares ...Middleware) http.Handler

ChainMiddleware a top-level middleware which applies the given middlewares in order from inner to outer (order of execution)

func ListMiddleware

func ListMiddleware[T ListParamParser](next http.Handler) http.Handler

func ParseId

func ParseId(val string) (string, error)

func ParseLimit

func ParseLimit(val string) (int, error)

func ParsePage

func ParsePage(val string) (int, error)

func ParseSortBy

func ParseSortBy(val string, listParamParser ListParamParser) (string, error)

func ParseValue

func ParseValue(val string, sortBy string, listParamParser ListParamParser) (interface{}, error)

Types

type GetDefaultSortByFunc

type GetDefaultSortByFunc func() string

type GetSupportedSortBys

type GetSupportedSortBys func() []string

type ListParamParser

type ListParamParser interface {
	GetDefaultSortBy() string
	GetSupportedSortBys() []string
	ParseValue(val string, sortBy string) (interface{}, error)
}

type ListParams

type ListParams struct {
	Page        int
	Limit       int
	Query       string
	SortBy      string
	SortOrder   SortOrder
	AfterId     string
	BeforeId    string
	AfterValue  interface{}
	BeforeValue interface{}
}

func GetListParamsFromContext

func GetListParamsFromContext(context context.Context) ListParams

func (ListParams) UseCursorPagination

func (lp ListParams) UseCursorPagination() bool

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware defines the type of all middleware

type SortOrder

type SortOrder int
const (
	SortOrderAsc  SortOrder = iota
	SortOrderDesc SortOrder = iota
)

func ParseSortOrder

func ParseSortOrder(val string) (SortOrder, error)

func (SortOrder) String

func (so SortOrder) String() string

Jump to

Keyboard shortcuts

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