router

package
v0.0.0-...-d331868 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2017 License: MIT Imports: 2 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitRoute

type BitRoute interface {

	// GET registers a new request handle for HTTP GET method.
	GET(path string, f func(Control))
	// PUT registers a new request handle for HTTP PUT method.
	PUT(path string, f func(Control))
	// POST registers a new request handle for HTTP POST method.
	POST(path string, f func(Control))
	// DELETE registers a new request handle for HTTP DELETE method.
	DELETE(path string, f func(Control))
	// HEAD registers a new request handle for HTTP HEAD method.
	HEAD(path string, f func(Control))
	// OPTIONS registers a new request handle for HTTP OPTIONS method.
	OPTIONS(path string, f func(Control))
	// PATCH registers a new request handle for HTTP PATCH method.
	PATCH(path string, f func(Control))

	// If enabled, the router automatically replies to OPTIONS requests.
	// Nevertheless OPTIONS handlers take priority over automatic replies.
	// By default this option is disabled
	UseOptionsReplies(bool)

	// SetupNotAllowedHandler defines own handler which is called when a request
	// cannot be routed.
	SetupNotAllowedHandler(func(Control))

	// SetupNotFoundHandler allows to define own handler for undefined URL path.
	// If it is not set, http.NotFound is used.
	SetupNotFoundHandler(func(Control))

	// SetupRecoveryHandler allows to define handler that called when panic happen.
	// The handler prevents your server from crashing and should be used to return
	// http status code http.StatusInternalServerError (500)
	SetupRecoveryHandler(func(Control))

	// SetupMiddleware defines handler that is allowed to take control
	// before it is called standard methods above e.g. GET, PUT.
	SetupMiddleware(func(func(Control)) func(Control))

	// Listen and serve on requested host and port e.g "0.0.0.0:8080"
	Listen(hostPort string) error
}

BitRoute interface contains base http methods e.g. GET, PUT, POST and defines your own handlers that is useful in some use cases

type Control

type Control interface {
	// Request returns *http.Request
	Request() *http.Request

	// Query searches URL/Post query parameters by key.
	// If there are no values associated with the key, an empty string is returned.
	Query(key string) string

	// Param sets URL/Post key/value query parameters.
	Param(key, value string)

	// Code sets HTTP status code e.g. http.StatusOk
	Code(code int)

	// GetCode shows HTTP status code that set by Code()
	GetCode() int

	// Body writes prepared header, status code and body data into http output.
	// It is equal to using sequence of http.ResponseWriter methods:
	// WriteHeader(code int) and Write(b []byte) int, error
	Body(data interface{})

	// Embedded response writer
	http.ResponseWriter
}

Control interface contains methods that control HTTP header, URL/post query parameters, request/response and HTTP output like Code(), Write(), etc.

type HTTPRouter

type HTTPRouter interface {

	// GET registers a new request handle for HTTP GET method.
	GET(path string, h httprouter.Handle)
	// PUT registers a new request handle for HTTP PUT method.
	PUT(path string, h httprouter.Handle)
	// POST registers a new request handle for HTTP POST method.
	POST(path string, h httprouter.Handle)
	// DELETE registers a new request handle for HTTP DELETE method.
	DELETE(path string, h httprouter.Handle)
	// HEAD registers a new request handle for HTTP HEAD method.
	HEAD(path string, h httprouter.Handle)
	// OPTIONS registers a new request handle for HTTP OPTIONS method.
	OPTIONS(path string, h httprouter.Handle)
	// PATCH registers a new request handle for HTTP PATCH method.
	PATCH(path string, h httprouter.Handle)

	// If enabled, the router automatically replies to OPTIONS requests.
	// Nevertheless OPTIONS handlers take priority over automatic replies.
	// By default this option is enabled
	UseOptionsReplies(bool)

	// SetupNotAllowedHandler defines own handler which is called when a request
	// cannot be routed.
	SetupNotAllowedHandler(http.Handler)

	// SetupNotFoundHandler allows to define own handler for undefined URL path.
	// If it is not set, http.NotFound is used.
	SetupNotFoundHandler(http.Handler)

	// SetupRecoveryHandler allows to define handler that called when panic happen.
	// The handler prevents your server from crashing and should be used to return
	// http status code http.StatusInternalServerError (500)
	// interface{} will contain value which is transmitted from panic call.
	SetupRecoveryHandler(func(http.ResponseWriter, *http.Request, interface{}))

	// Listen and serve on requested host and port e.g "0.0.0.0:8080"
	Listen(hostPort string) error
}

HTTPRouter interface contains base http methods e.g. GET, PUT, POST and defines your own handlers that is useful in some use cases

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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