Documentation
¶
Index ¶
Constants ¶
const ( DEFAULT_PORT_ENV_NAME = "YAWF_PORT_ENV_NAME" DEFAULT_HOST_ENV_NAME = "YAWF_HOST_ENV_NAME" )
Variables ¶
This section is empty.
Functions ¶
func ValidateHandler ¶
func ValidateHandler(handler Handler)
Types ¶
type BeforeFunc ¶
type BeforeFunc func(ResponseWriter)
BeforeFunc is a function that is called before the ResponseWriter has been written to.
type Context ¶
type Context interface {
inject.Injector
// Next is an optional function that Middleware Handlers can call to yield the until after
// the other Handlers have been executed. This works really well for any operations that must
// happen after an http request
Next()
// Written returns whether or not the response for this context has been written.
Written() bool
Stop()
IsStopped() bool
}
Context represents a request context. Services can be mapped on the request level from this interface.
func NewContext ¶
func NewContext(handlers []Handler, action Handler, res http.ResponseWriter) Context
type FormParams ¶
type MiddlewareReturnHandler ¶
type PathParams ¶
Params is a map of name/value pairs for named routes. An instance of yawf.Params is available to be injected into any route handler.
type QueryParams ¶
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Flusher
http.Hijacker
// Status returns the status code of the response or 0 if the response has not been written.
Status() int
// Written returns whether or not the ResponseWriter has been written.
Written() bool
// Size returns the size of the response body.
Size() int
// Before allows for a function to be called before the ResponseWriter has been written to. This is
// useful for setting headers or any other operations that must happen before a response has been written.
Before(BeforeFunc)
}
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(res http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type Route ¶
type Route interface {
// URLWith returns a rendering of the Route's url with the given string params.
URLWith([]string) string
// SetName sets a name for the route.
SetName(string)
// Name returns the name of the route.
Name() string
// Pattern returns the pattern of the route.
Pattern() string
// Method returns the method of the route.
Method() string
}
Route is an interface representing a Route in Yawf's routing layer.
type RouteMatch ¶
type RouteMatch int
const ( NoMatch RouteMatch = iota StarMatch OverloadMatch ExactMatch )
func (RouteMatch) BetterThan ¶
func (r RouteMatch) BetterThan(o RouteMatch) bool
Higher number = better match
type Router ¶
type Router interface {
Routes
// Group adds a group where related routes can be added.
Group(string, func(Router), ...Handler)
// Get adds a route for a HTTP GET request to the specified matching pattern.
Get(string, ...Handler) Route
// Patch adds a route for a HTTP PATCH request to the specified matching pattern.
Patch(string, ...Handler) Route
// Post adds a route for a HTTP POST request to the specified matching pattern.
Post(string, ...Handler) Route
// Put adds a route for a HTTP PUT request to the specified matching pattern.
Put(string, ...Handler) Route
// Delete adds a route for a HTTP DELETE request to the specified matching pattern.
Delete(string, ...Handler) Route
// Options adds a route for a HTTP OPTIONS request to the specified matching pattern.
Options(string, ...Handler) Route
// Head adds a route for a HTTP HEAD request to the specified matching pattern.
Head(string, ...Handler) Route
// Any adds a route for any HTTP method request to the specified matching pattern.
Any(string, ...Handler) Route
// AddRoute adds a route for a given HTTP method request to the specified matching pattern.
AddRoute(string, string, ...Handler) Route
// NotFound sets the handlers that are called when a no route matches a request. Throws a basic 404 by default.
NotFound(...Handler)
// Handle is the entry point for routing. This is used as a yawf.Handler
Handle(http.ResponseWriter, *http.Request, Context)
}
Router is Yawf's de-facto routing interface. Supports HTTP verbs, stacked handlers, and dependency injection.
type RouterReturnHandler ¶
ReturnHandler is a service that Yawf provides that is called when a route handler returns something. The ReturnHandler is responsible for writing to the ResponseWriter based on the values that are passed into this function.
type Routes ¶
type Routes interface {
// URLFor returns a rendered URL for the given route. Optional params can be passed to fulfill named parameters in the route.
URLFor(name string, params ...interface{}) string
// MethodsFor returns an array of methods available for the path
MethodsFor(path string) []string
// All returns an array with all the routes in the router.
All() []Route
}
Routes is a helper service for Yawf's routing layer.
type YawfServer ¶
type YawfServer interface {
Router
Use(Handler)
SetAddress(address string)
Address() string
SetListener(net.Listener)
Listener() net.Listener
Listen() error
Run() error
RunOnAddress(string) error
SetLogger(*log.Logger)
Logger() *log.Logger
Stop()
SetGracefulDelay(time.Duration)
}
func New ¶
func New() YawfServer