reflection

package
v0.0.0-...-2b8a88d Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequiredJSONBody = fmt.Errorf("expected a request body")

Functions

func HandlerFromFn

func HandlerFromFn(fptr interface{}, fn RequestHandler, components openapi.Components, c *container.Container) (http.HandlerFunc, error)

HandlerFromFn takes in any function matching the following criteria: 1. Takes the following as input:

  • context.Context
  • *http.Request
  • http.ResponseWriter
  • any other type that is passed in via the ArgCreators map

2. Returns up to two responses

  • last return of this function must be an error

The second argument is a function to ErrorHandler to handle any errors during the http.Handler All arguments will be automatically created and supplied to the function. Only loads params and one json body schema in the components.

func HandlerFromFnDefault

func HandlerFromFnDefault(fnPtr interface{}, fn RequestHandler, components openapi.Components) (http.HandlerFunc, error)

Types

type Hooks

type Hooks struct {
	// BeforeOptions is called before the options are passed into the operation.
	// The returned operation will be used in place of the original
	BeforeOptions func(method, pattern string, handler interface{}, options []operations.Option) (operations.Options, error)

	// BeforeMiddleware is called before the handler is wrapped with the middleware.
	// The returned middleware will be used in place of the original
	BeforeMiddleware func(method, pattern string, handler interface{}, c *ReflectRouter, middleware []Middleware) ([]Middleware, error)
}

type Middleware

type Middleware func(next http.Handler) http.Handler

type QueryParamError

type QueryParamError struct {
	Name     string
	Location string
	Reason   string
	Input    string
}

func (QueryParamError) Error

func (e QueryParamError) Error() string

type ReflectRouter

type ReflectRouter struct {
	*router.Router
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *ReflectRouter

NewRouter returns a wrapped chi router

func (*ReflectRouter) Connect

func (r *ReflectRouter) Connect(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Container

func (r *ReflectRouter) Container() *container.Container

FIXME: remove this?

func (*ReflectRouter) Delete

func (r *ReflectRouter) Delete(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Get

func (r *ReflectRouter) Get(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Head

func (r *ReflectRouter) Head(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) MethodFunc

func (r *ReflectRouter) MethodFunc(method, pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

MethodFunc adds routes for `pattern` that matches the `method` HTTP method. Middleware are executed from first to last

func (*ReflectRouter) Mount

func (r *ReflectRouter) Mount(pattern string, handler http.Handler)

Mount attaches another http.Handler along ./pattern/*

func (*ReflectRouter) Options

func (r *ReflectRouter) Options(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Patch

func (r *ReflectRouter) Patch(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Post

func (r *ReflectRouter) Post(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Provide

func (r *ReflectRouter) Provide(fptr interface{}) error

func (*ReflectRouter) Put

func (r *ReflectRouter) Put(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) Route

func (r *ReflectRouter) Route(pattern string, fn func(*ReflectRouter))

Route mounts a sub-Router along a `pattern“ string.

func (*ReflectRouter) SetParent

func (r *ReflectRouter) SetParent(parent *ReflectRouter) *ReflectRouter

func (*ReflectRouter) Trace

func (r *ReflectRouter) Trace(pattern string, handler interface{}, options []operations.Option, middleware ...Middleware)

func (*ReflectRouter) UseRouter

func (r *ReflectRouter) UseRouter(other *ReflectRouter) *ReflectRouter

UseRouter copies over the routes and swagger info from the other router.

func (*ReflectRouter) WithContainer

func (r *ReflectRouter) WithContainer(c *container.Container) *ReflectRouter

func (*ReflectRouter) WithHandler

func (r *ReflectRouter) WithHandler(fn RequestHandler) *ReflectRouter

func (*ReflectRouter) WithHooks

func (r *ReflectRouter) WithHooks(h Hooks) *ReflectRouter

func (*ReflectRouter) WithInfo

func (r *ReflectRouter) WithInfo(info openapi.Info) *ReflectRouter

type RequestHandler

type RequestHandler func(w http.ResponseWriter, r *http.Request, response interface{}, err error)

Jump to

Keyboard shortcuts

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