Documentation
¶
Index ¶
- Variables
- func BootAndExit(name string, initializer RouteInitializer)
- func NewInitializer(initializer RouteInitializer, configs ...RouterConfigFunc) basehttp.ServerInitializer
- type EmptySpec
- func (es *EmptySpec) Delete(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- func (es *EmptySpec) Get(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- func (es *EmptySpec) Options(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- func (es *EmptySpec) Patch(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- func (es *EmptySpec) Post(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- func (es *EmptySpec) Put(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
- type Handler
- type Method
- type Middleware
- type MiddlewareConfigFunc
- type MiddlewareFunc
- type Resource
- type ResourceSpec
- type RouteInitializer
- type RouteInitializerFunc
- type Router
- type RouterConfigFunc
- type ServerInitializer
Constants ¶
This section is empty.
Variables ¶
var TokenNotImplementedHandler = tokenNotImplementedHandler("chevron.not_implemented_handler")
TokenNotImplementedHandler is the unique token to which the router's not implemented handler is written to the request context.
Functions ¶
func BootAndExit ¶
func BootAndExit(name string, initializer RouteInitializer)
BootAndExit creates a nacelle Bootstrapper with the given name and registers an HTTP server with the given route initializer. This method does not return.
func NewInitializer ¶
func NewInitializer(initializer RouteInitializer, configs ...RouterConfigFunc) basehttp.ServerInitializer
NewInitializer creates a new ServerInitializer.
Types ¶
type EmptySpec ¶
type EmptySpec struct{}
EmptySpec is a complete implementation of ResourceSpec that invokes the router's not implemented handler. A pointer to this struct should be the first embedded field in any resource - this allows a resource to simply "override" the handlers for methods relevant to a resource.
func (*EmptySpec) Delete ¶
func (es *EmptySpec) Delete(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
Delete invokes the router's not implemented handler.
func (*EmptySpec) Get ¶
func (es *EmptySpec) Get(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
Get invokes the router's not implemented handler.
func (*EmptySpec) Options ¶
func (es *EmptySpec) Options(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
Options invokes the router's not implemented handler.
func (*EmptySpec) Patch ¶
func (es *EmptySpec) Patch(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response
Patch invokes the router's not implemented handler.
type Handler ¶
Handler converts an HTTP request into a response object. The handler also has access to a request context populated by the router and registered middleware as well as a request logger which may also be decorated by registered middleware.
func GetNotImplementedHandler ¶
GetNotImplementedHandler retrieves the router's not implemented handler from the given context. If no handler is registered with this context, the default handler is returned.
type Method ¶
type Method int
Method is an enumeration of HTTP methods.
const ( // MethodGet represents the GET HTTP method. MethodGet Method = iota // MethodOptions represents the OPTIONS HTTP method. MethodOptions // MethodPost represents the POST HTTP method. MethodPost // MethodPut represents the PUT HTTP method. MethodPut // MethodPatch represents the PATCH HTTP method. MethodPatch // MethodDelete represents the DELETE HTTP method. MethodDelete )
type Middleware ¶
type Middleware interface { // Convert applies the middleware transformation to a handler. If // the middleware is supplied invalid arguments it may return an // error at the time of decoration. Convert(Handler) (Handler, error) }
Middleware transforms a handler into another decorated handler.
type MiddlewareConfigFunc ¶
type MiddlewareConfigFunc func(handlerMap) error
MiddlewareConfigFunc is a function that decorates a map from HTTP methods to handlers.
func WithMiddleware ¶
func WithMiddleware(middleware Middleware) MiddlewareConfigFunc
WithMiddleware applies the given middleware to all HTTP methods in the handler map.
func WithMiddlewareFor ¶
func WithMiddlewareFor(middleware Middleware, methods ...Method) MiddlewareConfigFunc
WithMiddlewareFor applies the given middleware to the provided HTTP methods in the handler map.
type MiddlewareFunc ¶
MiddlewareFunc is signature for single-function middleware.
type Resource ¶
type Resource interface { // Handle is invoked when the resource is requested, regardless of the // HTTP method. Handle(context.Context, *http.Request, nacelle.Logger) response.Response }
Resource represents an object or behavior accessible from a unique URL pattern.
type ResourceSpec ¶
type ResourceSpec interface { // Get is the handler invoked for the GET HTTP method. Get(context.Context, *http.Request, nacelle.Logger) response.Response // Options is the handler invoked for the OPTIONS HTTP method. Options(context.Context, *http.Request, nacelle.Logger) response.Response // Post is the handler invoked for the POST HTTP method. Post(context.Context, *http.Request, nacelle.Logger) response.Response // Put is the handler invoked for the PUT HTTP method. Put(context.Context, *http.Request, nacelle.Logger) response.Response // Patch is the handler invoked for the PATCH HTTP method. Patch(context.Context, *http.Request, nacelle.Logger) response.Response // Delete is the handler invoked for the DELETE HTTP method. Delete(context.Context, *http.Request, nacelle.Logger) response.Response }
ResourceSpec represents the set of handlers (one for each HTTP method) to which a resource can respond.
type RouteInitializer ¶
type RouteInitializer interface { // Init registers resources and middleware to the router. Init(config nacelle.Config, router Router) error }
RouteInitializer initializes a Router instance.
type RouteInitializerFunc ¶
RouteInitializerFunc is a function conforming to the RouteInitializer interface.
type Router ¶
type Router interface { http.Handler // AddMiddleware registers middleware for all resources registered after // the invocation of this method. AddMiddleware(middleware Middleware) // Register creates a resource from the given resource spec and set of // middleware instances and registers it to the given URL pattern. Register(url string, spec ResourceSpec, configs ...MiddlewareConfigFunc) error // MustRegister calls Register and panics on error. MustRegister(url string, spec ResourceSpec, configs ...MiddlewareConfigFunc) RegisterHandler(url string, handler http.Handler) }
Router stores
func NewRouter ¶
func NewRouter(services nacelle.ServiceContainer, configs ...RouterConfigFunc) Router
NewRouter creates a new router.
type RouterConfigFunc ¶
type RouterConfigFunc func(*router)
RouterConfigFunc is a function used to initialize a new router.
func WithLogger ¶
func WithLogger(logger nacelle.Logger) RouterConfigFunc
WithLogger sets the router's logger.
func WithNotFoundHandler ¶
func WithNotFoundHandler(handler Handler) RouterConfigFunc
WithNotFoundHandler sets the handler invoked when a requested URL cannot be matched with any registered URL pattern.
func WithNotImplementedHandler ¶
func WithNotImplementedHandler(handler Handler) RouterConfigFunc
WithNotImplementedHandler sets the handler invoked when a resource does not implemented the requested HTTP verb.
type ServerInitializer ¶
type ServerInitializer struct { Services nacelle.ServiceContainer `service:"container"` Logger nacelle.Logger `service:"logger"` // contains filtered or unexported fields }
ServerInitializer implements basehttp.ServerInitializer.