describer

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2017 License: MIT Imports: 6 Imported by: 0

README

describer

Middleware that enables self-describing RESTful APIs for chi router.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHijackOptions = HijackOptions{
	ContentType: "application/json",
	Render:      json.Marshal,
}

DefaultHijackOptions is used as Middleware options if no other options are specified.

Default encoding is JSON.

Functions

func Middleware

func Middleware(options ...HijackOptions) func(http.Handler) http.Handler

Middleware is a middleware that enables automatic routing schema self-description, when making an "OPTIONS" HTTP request to the chi.Router instance that uses this middleware.

The HTTP Response this middleware produces contains an Routes object. See the documentation

Options can be passed through by using an HijackOptions object to this function. Keep in mind that only the first passed HijackOptions instance will be used as actual options.

Types

type HijackOptions

type HijackOptions struct {
	ContentType string
	Render      RenderFn
}

HijackOptions specifies options for the Middleware middleware, such as:

  • "Content-Type" header and serialization function
  • Policy check logic to hide sensible paths from unauthorized users

type RenderFn

type RenderFn func(v interface{}) ([]byte, error)

RenderFn is a function that takes the output of the middleware and serialize it in a certain encoding.

type RouteInfo

type RouteInfo struct {
	Method      string `json:"method"`
	Path        string `json:"uri"`
	Description string `json:"description,omitempty"`
}

RouteInfo is the representation of a API HTTP Route.

type Routes

type Routes []RouteInfo

Routes is the list of all API routes detected from the middlware.

func (Routes) Len

func (r Routes) Len() int

func (Routes) Less

func (r Routes) Less(i int, j int) bool

func (Routes) Swap

func (r Routes) Swap(i int, j int)

Jump to

Keyboard shortcuts

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