Documentation ¶
Overview ¶
Package rest provides operations to implement a RESTful API.
Route ¶
A Route provides a easy way to define HTTP routes and handle it.
Rest ¶
A Rest provides an URL router for a RESTful API.
Route ¶
A Route provides a easy way to define HTTP routes and handle it.
Index ¶
- Constants
- func RecoverHandlerJson(next http.Handler) http.Handler
- type CORSHandler
- type CORSMiddleware
- type CORSPreflight
- type Rest
- func (rest *Rest) AddMiddlewarePrivate(m web.MiddlewareFunc)
- func (rest *Rest) AddMiddlewarePublic(m web.MiddlewareFunc)
- func (rest *Rest) AddResource(r Routable)
- func (rest *Rest) EnableCORS()
- func (rest *Rest) ResourcesRoutes() Routes
- func (rest *Rest) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type Routable
- type Route
- type RouteVars
- type Routes
Constants ¶
const ( DEFAULT_CORS_PREFLIGHT_METHOD = "OPTIONS" DEFAULT_CORS_MAX_AGE = time.Hour * 24 / time.Second DEFAULT_CORS_METHODS = "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT" DEFAULT_CORS_ORIGIN = "*" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CORSHandler ¶
type CORSHandler struct { PredicateOrigin dot.PredicateStringFunc Headers []string ExposedHeaders []string }
A CORSHandler allows to create a CORS-able API.
func NewCORSHandler ¶
func NewCORSHandler() *CORSHandler
NewCORSHandler creates a new CORSHandler with default values.
func (*CORSHandler) CreatePreflight ¶
func (s *CORSHandler) CreatePreflight(routes Routes) Routes
CreatePreflight creates HTTP routes that handles pre-flight requests.
type CORSMiddleware ¶
type CORSMiddleware struct { CORSHandler UseCredentials bool }
A CORSMiddleware represents a HTTP middleware that handle HTTP headers for CORS-able API.
type CORSPreflight ¶
type CORSPreflight struct { CORSHandler Methods []string UseCredentials bool }
A CORSPreflight represents a HTTP server that handles pre-flight requests.
func (*CORSPreflight) ServeHTTP ¶
func (s *CORSPreflight) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handle a pre-flight request.
type Rest ¶
type Rest struct {
// contains filtered or unexported fields
}
A Rest register resources and middlewares for a HTTP handler.
It implements the http.Handler interface, so it can be registered to serve requests.
func (*Rest) AddMiddlewarePrivate ¶
func (rest *Rest) AddMiddlewarePrivate(m web.MiddlewareFunc)
AddMiddlewarePrivate adds a layer to handle private resource requests.
func (*Rest) AddMiddlewarePublic ¶
func (rest *Rest) AddMiddlewarePublic(m web.MiddlewareFunc)
AddMiddlewarePublic adds a layer to handle public resource requests.
func (*Rest) AddResource ¶
AddResource adds a new REST-resource to handle requests.
func (*Rest) EnableCORS ¶
func (rest *Rest) EnableCORS()
EnableCORS allows to current API support CORS specification.
func (*Rest) ResourcesRoutes ¶
Routes returns the routes from registered resources.
type Routable ¶
type Routable interface {
Routes() Routes
}
The Routable interface is implemented by objects that has HTTP routes.
type Route ¶
type Route struct { // Unique name to current route. Name string // HTTP method handled by this route. Method string // HTTP path handled by this route. Path string // Indicates whether authentication is required to call this route. MustAuth bool // Defines which method is called to handle this route. ActionFunc http.HandlerFunc }
A Route represents a HTTP route.
type RouteVars ¶
A RouteVars represents the route variables for specified request.
func (RouteVars) GetObjectId ¶
GetObjectId tries to gets the value for specified key as BSON ObjectId.