router

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(routes []*Route) (*mux.Router, error)

New takes a list of routes and attempts to return a router with all of these routes registered to it.

Types

type ErrInvalidWeight added in v0.1.0

type ErrInvalidWeight struct {
	// contains filtered or unexported fields
}

ErrInvalidWeight is thrown when a handler has a weight outside the acceptable bounds.

func (ErrInvalidWeight) Error added in v0.1.0

func (e ErrInvalidWeight) Error() string

type Handler

type Handler struct {
	Weight          int               `yaml:"weight"`
	ResponseHeaders map[string]string `yaml:"response_headers"`
	StaticResponse  string            `yaml:"static_response"`
	ResponseStatus  int               `yaml:"response_status"`
	ResponsePath    string            `yaml:"response_path"`
	// contains filtered or unexported fields
}

Handler includes all the metadata to decide on and serve a response.

func (*Handler) ServeHTTP

func (handler *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface eventually serving a request.

type Route

type Route struct {
	Path           string                       `yaml:"path"`
	Method         string                       `yaml:"method"`
	QueryParams    map[string]string            `yaml:"query_params"`
	RequestHeaders map[string]string            `yaml:"request_headers"`
	Middleware     map[string]map[string]string `yaml:"middleware"`
	Handlers       []Handler                    `yaml:"handlers"`
	// contains filtered or unexported fields
}

Route includes all routing data to build a route and forward to an appropriate router. This is handed off to the router for the live routing.

func (*Route) Init

func (route *Route) Init() error

Init performs any setup and initialization around the route.

func (*Route) ServeHTTP

func (route *Route) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for pipelining a request further into a handler.

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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