Documentation
¶
Index ¶
- Variables
- func RegisterExtraParameter(key string, obj interface{})
- func RegisterHandler(h URLHandler, url string)
- func RegisterStaticHandler(url, directoryRoot string)
- type BadRequestError
- type DefaultHandler
- func (url DefaultHandler) Delete(r *http.Request, params map[string]interface{}) (string, error)
- func (url DefaultHandler) ETag(r *url.URL, params map[string]interface{}) (ETag, error)
- func (url DefaultHandler) Get(r *http.Request, params map[string]interface{}) (string, error)
- func (url DefaultHandler) LastModified(r *url.URL, params map[string]interface{}) time.Time
- func (url DefaultHandler) Post(r *http.Request, params map[string]interface{}) (string, string, error)
- func (url DefaultHandler) Put(r *http.Request, params map[string]interface{}) (string, error)
- type ETag
- type ForbiddenError
- type InvalidMethodError
- type NotFoundError
- type URLHandler
Constants ¶
This section is empty.
Variables ¶
var UnknownMTime time.Time = time.Time{}
Functions ¶
func RegisterExtraParameter ¶
func RegisterExtraParameter(key string, obj interface{})
RegisterExtraParameter allows you to add arbitrary data to get passed to the params parameter of URLHandler handler functions which you can retrieve from params[key] (and will need to manually cast to the appropriate type.
This is useful for passing, for instance, a pointer to an sql.DB, or any configuration data you want to use throughout your web app
func RegisterHandler ¶
func RegisterHandler(h URLHandler, url string)
RegisterHandler takes a URLHandler and a url string and registers that URLHandler to handle that URL. It automatically registers an http.HandleFunc which delegates to the appropriate URLHandler method
func RegisterStaticHandler ¶
func RegisterStaticHandler(url, directoryRoot string)
RegisterStaticHandler registers directory to be served by the web server on the filesystem without going through the handler function.
Types ¶
type BadRequestError ¶
type BadRequestError struct{}
func (BadRequestError) Error ¶
func (r BadRequestError) Error() string
type DefaultHandler ¶
type DefaultHandler struct{}
DefaultHandler is an simple implementation of the URLHandler interface that you can compose into your class if you only want to implement some methods. The DefaultHandler will respond with a 405 Method Not Allowed response to every request.
func (DefaultHandler) LastModified ¶
type ForbiddenError ¶
type ForbiddenError struct{}
func (ForbiddenError) Error ¶
func (r ForbiddenError) Error() string
type InvalidMethodError ¶
type InvalidMethodError struct{}
func (InvalidMethodError) Error ¶
func (r InvalidMethodError) Error() string
type NotFoundError ¶
type NotFoundError struct{}
func (NotFoundError) Error ¶
func (r NotFoundError) Error() string
type URLHandler ¶
type URLHandler interface {
// Get will handle an HTTP GET request to this URL and return the
// content that should be sent to the client
Get(r *http.Request, params map[string]interface{}) (string, error)
// Post will handle an HTTP POST request to this URL.
// Post returns 2 strings: the content to return, an a redirectURL
// If the redirectURL is not the empty string, the registered
// URLandler will automatically respond with a 303 return code
// instead of a 200 return code, and set an appropriate Location:
// response header
Post(r *http.Request, params map[string]interface{}) (content, redirectURL string, err error)
// Put will handle an HTTP PUT request to this URL and return the
// content that should be sent to the client
Put(r *http.Request, params map[string]interface{}) (string, error)
// Delete will handle an HTTP PUT request to this URL and return the
// content that should be sent to the client
Delete(r *http.Request, params map[string]interface{}) (string, error)
// Calculate an ETag to represent the resource being served by
// this handler, so that a registered handler can return a 304
// code if the resource hasn't changed.
ETag(*url.URL, map[string]interface{}) (ETag, error)
LastModified(*url.URL, map[string]interface{}) time.Time
}
URLHandler is an interface to describe a request to a URL
After being registered to handle a URL with a RegisterHandler call, the URLHandler will handle any requests to that URL by delegating to the method for the appropriate HTTP Method being called.
All methods receive the http.Request object, and a map of extra parameters that have been registered with RegisterExtraParameter