router

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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InputKey = ctxKey{"input"}

InputKey is used to get the *openapi3filter.RequestValidationInput{} from a ctx

Functions

func SetOpenAPIInput

func SetOpenAPIInput(router routers.Router, optionsFn func(r *http.Request, options *openapi3filter.Options)) func(http.Handler) http.Handler

func VerifyRequest

func VerifyRequest(errFn ErrorHandler) func(http.Handler) http.Handler

VerifyRequest validates requests against matching openapi routes; Requires SetOpenAPIInput middleware to have been called

func VerifyResponse

func VerifyResponse(errFn ErrorHandler) func(http.Handler) http.Handler

VerifyResponse validates response against matching openapi routes Requires SetOpenAPIInput middleware to have been called

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request, error)

type Router

type Router struct {
	Mux     chi.Router
	OpenAPI openapi.OpenAPI
	// contains filtered or unexported fields
}

Router is a small wrapper over a chi.Router to help generate an openapi spec

func NewRouter

func NewRouter() *Router

NewRouter returns a wrapped chi router

func (*Router) Components

func (r *Router) Components() openapi.Components

func (*Router) Connect

func (r *Router) Connect(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Delete

func (r *Router) Delete(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) FilterRouter

func (r *Router) FilterRouter() (routers.Router, error)

FilterRouter returns a router used for verifying middlewares

func (*Router) GenerateSpec

func (r *Router) GenerateSpec() (string, error)

func (*Router) Get

func (r *Router) Get(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Head

func (r *Router) Head(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Method

func (r *Router) Method(method, pattern string, handler http.Handler, options []operations.Option)

Method adds routes for `pattern` that matches the `method` HTTP method.

func (*Router) MethodFunc

func (r *Router) MethodFunc(method, pattern string, handler http.HandlerFunc, options []operations.Option)

MethodFunc adds routes for `pattern` that matches the `method` HTTP method.

func (*Router) Mount

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

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

func (*Router) Options

func (r *Router) Options(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Patch

func (r *Router) Patch(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Post

func (r *Router) Post(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Put

func (r *Router) Put(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) RegisterType

func (r *Router) RegisterType(obj interface{}, schema *openapi3.Schema)

RegisterType registers the type as an inline schema

func (*Router) RegisterTypeAsComponent

func (r *Router) RegisterTypeAsComponent(obj interface{}, name string, schema *openapi3.Schema)

RegisterTypeAsComponent registers the objects type as a reference to the schema, which is inserted into the schema.components with the supplied name

func (*Router) RegisterTypeAsRef

func (r *Router) RegisterTypeAsRef(obj interface{}, name string) error

RegisterTypeAsRef registers the objects type as a reference to the schema located in schema.components with the supplied name

func (*Router) Route

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

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

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) SetDefaultJSON

func (r *Router) SetDefaultJSON(description string, obj interface{})

SetDefaultJSON will set the default response for all routes unless overridden at the operation level

func (*Router) SetGlobalSecurity

func (r *Router) SetGlobalSecurity(name string) *Router

func (*Router) SetStatusDefault

func (r *Router) SetStatusDefault(status int, description string, obj interface{})

SetStatusDefault will set the statusCode for all routes to the supplied object.

func (*Router) Trace

func (r *Router) Trace(pattern string, handler http.HandlerFunc, options []operations.Option)

func (*Router) Use

func (r *Router) Use(middlewares ...func(http.Handler) http.Handler)

Use appends one or more middlewares onto the Router stack.

func (*Router) UseRouter

func (r *Router) UseRouter(other *Router) *Router

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

func (*Router) ValidateSpec

func (r *Router) ValidateSpec() error

func (*Router) With

func (r *Router) With(middlewares ...func(http.Handler) http.Handler) *Router

With adds inline middlewares for an endpoint handler.

func (*Router) WithInfo

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

func (*Router) WithSecurity

func (r *Router) WithSecurity(security SecuritySchema) *Router

type SecuritySchema

type SecuritySchema struct {
	Name                         string
	SchemeName, Type, Scheme, In string
}

SecuritySchema represents an openapi3 security scheme

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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