Documentation ¶
Overview ¶
Package web provides utilities for working with go's net/http package.
Index ¶
- func HandleCors(allowedOrigin string, h http.Handler) http.Handler
- func HandleResource(root Resource) http.HandlerFunc
- func HandleResourceWithContext(root Resource, xform func(context.Context) context.Context) http.HandlerFunc
- type Error
- type MethodHandler
- type Port
- type Resource
- type Status
- type Wrapper
- func (n *Wrapper) Find(child string) (ret Resource)
- func (n *Wrapper) Get(ctx context.Context, w http.ResponseWriter) (err error)
- func (n *Wrapper) Post(ctx context.Context, r io.Reader, w http.ResponseWriter) (err error)
- func (n *Wrapper) Put(ctx context.Context, r io.Reader, w http.ResponseWriter) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleCors ¶
Allow some remote origin access to the specified handler.
func HandleResource ¶
func HandleResource(root Resource) http.HandlerFunc
HandleResource turns a Resource into an http.HandlerFunc; providing responses to http get and post requests.
func HandleResourceWithContext ¶
func HandleResourceWithContext(root Resource, xform func(context.Context) context.Context) http.HandlerFunc
HandleResource turns a Resource into an http.HandlerFunc; providing responses to http get and post requests.
Types ¶
type Error ¶
type Error struct {
Message error
}
Error generates an error for every endpoint.
type MethodHandler ¶
implements a handler per method. ( doesnt attempt to validate method names, and doesn't notice duplicate registration. last one wins )
func (MethodHandler) ServeHTTP ¶
func (m MethodHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Port ¶
type Port int
implements the flag.Value interface for reading ports from the command line by default will return the default port ( and true )
type Resource ¶
type Resource interface { // Return the named child resource Find(string) Resource // Read a resource Get(context.Context, http.ResponseWriter) error // Alter a resource Post(context.Context, io.Reader, http.ResponseWriter) error // Receive a resource Put(context.Context, io.Reader, http.ResponseWriter) error }
Resource interfaces with a rest-ish endpoint, there are methods for each major verb. See also Wrapper which provides a function-based adapter for creating resources.
type Wrapper ¶
type Wrapper struct { Finds func(string) Resource Gets func(context.Context, http.ResponseWriter) error Posts func(context.Context, io.Reader, http.ResponseWriter) error Puts func(context.Context, io.Reader, http.ResponseWriter) error }
Turn one or more Resource compatible functions into a full interface implementation.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package js provides some simple json utilities: MapSlice, for preserving map key order when unmarshaling, and Builder for writing json-like data without marshaling.
|
Package js provides some simple json utilities: MapSlice, for preserving map key order when unmarshaling, and Builder for writing json-like data without marshaling. |
Package markup converts a custom html-like markup into markdown-like text.
|
Package markup converts a custom html-like markup into markdown-like text. |
Package useraction: handle long running actions initiated from the browser.
|
Package useraction: handle long running actions initiated from the browser. |