Documentation ¶
Overview ¶
Package httpentity provides a "framework" for exposing resources over HTTP.
Within the framework, an "Entity" is simply something that can be accessed over HTTP. A "NetEntity" is something that is capable of being transmitted as an HTTP body--most Entities will also be NetEntities. But, things like error messages are NetEntities, but aren't Entities, as it's not a normal thing that you can request.
An Entity is accessed using the method allowed in (*Entity).Methods(). An entity may also have children--these are accessed with (*Entity).Subentities(childName, request).
A Router is the entire Entity tree; it mostly just takes the root Entity of the tree. It handles dispatching Requests to the correct Entity, then formatting the Responses to the output stream.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncoderJSON ¶
type EncoderJSON struct {
Data interface{}
}
func (EncoderJSON) IsText ¶
func (e EncoderJSON) IsText() bool
func (EncoderJSON) Locales ¶
func (e EncoderJSON) Locales() []locale.Spec
type EncoderJSONStr ¶
func (EncoderJSONStr) IsText ¶
func (e EncoderJSONStr) IsText() bool
func (EncoderJSONStr) Locales ¶
func (e EncoderJSONStr) Locales() []locale.Spec
type EncoderTXT ¶
func (EncoderTXT) IsText ¶
func (e EncoderTXT) IsText() bool
func (EncoderTXT) Locales ¶
func (e EncoderTXT) Locales() []locale.Spec
type Entity ¶
type Entity interface { // Methods() returns a map of HTTP request methods to Handlers // that handle requests for this Entity. Methods() map[string]func(Request) Response }
An Entity is some resource that is accessible over HTTP.
type EntityExtra ¶
EntityExtra is an Entity that provides a custom HTTP 405 ("Method Not Allowed") handler.
type EntityGroup ¶
type EntityGroup interface { Entity // Subentity(name, request) returns the child of this entity // with the name `name`, or nil if a child with that name // doesn't exist. // // The Request is included in the function call so that it can // be determined if the user has permission to access that // child. Subentity(name string, request Request) Entity // SubentityNotFound is called if Subentity returns nil. If // the name contains a slash; it indicates that the child was // found, but a grandchild was requested, and the child wasn't // an EntityGroup. SubentityNotFound(name string, request Request) Response }
An EntityGroup is an Entity that also has child entities (i.e., a directory or folder).
type Logger ¶
type Logger interface { Printf(format string, v ...interface{}) Println(v ...interface{}) }
type Middleware ¶
type Middleware struct { // Outside is able to affect the entity that is looked up Outside func(Request, func(Request) Response) Response // Inside cannot affect the entity that is looked up, but it // gets to inspect the entity. Inside func(Request, Entity, func(Request, Entity) Response) Response }
A Middleware is something that wraps the request handler.
type NetEntity ¶
type NetEntity interface { // Encoders() returns a map of MIME-types to encoders that // serialize the NetEntity to that type. Encoders() map[string]Encoder }
A NetEntity is just something that is capable of being transmitted over the network (in a variety of formats).
type NetJSON ¶
type NetJSON struct {
Data interface{}
}
type NetLocations ¶
func (NetLocations) Encoders ¶
func (l NetLocations) Encoders() map[string]Encoder
Encoders fulfills the httpentity.NetEntity interface.
func (NetLocations) IsText ¶
func (l NetLocations) IsText() bool
func (NetLocations) Locales ¶
func (l NetLocations) Locales() []locale.Spec
type NetStringer ¶
NetString is a string that implements httpentity.NetEntity.
func NetPrintf ¶
func NetPrintf(format string, a ...interface{}) NetStringer
NetPrintf is fmt.Sprintf as a NetString.
func (NetStringer) Encoders ¶
func (s NetStringer) Encoders() map[string]Encoder
Encoders fulfills the httpentity.NetEntity interface.
type Request ¶
type Request struct { Method string URL *url.URL Headers http.Header Entity interface{} Things map[string]interface{} // Objects added by middlewares // contains filtered or unexported fields }
Request is an incoming HTTP request to be handled.
type Response ¶
type Response struct { Status int16 Headers http.Header Entity NetEntity InhibitNotAcceptable bool InhibitMultipleChoices bool // contains filtered or unexported fields }
The Response to an HTTP request.
type RootEntity ¶
type RootEntity interface { Entity Subentity(name string, request Request) Entity SubentityNotFound(name string, request Request) Response MethodNotAllowed(request Request) Response }
RootEntity is the union of EntityGroup and EntityExtra.
type Router ¶
type Router struct { Prefix string Root RootEntity Decoders map[string]func(io.Reader, map[string]string) (interface{}, locale.Error) Middlewares []Middleware // Whether to include stacktraces in HTTP 500 responses Stacktrace bool Log Logger // Whether to trust `X-Forwarded-Scheme:` and RFC 7239 // `Forwarded: proto=` TrustForwarded bool MethodNotAllowed func(entity Entity, request Request) Response // contains filtered or unexported fields }
A Router represents the root of an Entity tree, and handles reading and writing messages to the network socket.