Documentation
¶
Overview ¶
package data provides wrappers for response data, optionally including response headers such as ETag and Cache-Control.
Index ¶
- func GetContentAndApplyExtraHeaders(rw http.ResponseWriter, d Data, template, language string) (interface{}, error)
- type Data
- type Value
- func (v Value) Content(template, language string) (result interface{}, err error)
- func (v Value) ETag(fn func(interface{}) string, weak ...bool) Value
- func (v Value) Expires(at time.Time) Value
- func (v Value) Headers() map[string]interface{}
- func (v Value) LastModified(at time.Time) Value
- func (v Value) MaxAge(max time.Duration) Value
- func (v Value) NoCache() Value
- func (v Value) With(hdr string, value interface{}, others ...interface{}) Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetContentAndApplyExtraHeaders ¶ added in v0.9.0
func GetContentAndApplyExtraHeaders(rw http.ResponseWriter, d Data, template, language string) (interface{}, error)
GetContentAndApplyExtraHeaders applies all lazy functions to produce the resulting content to be rendered; this value is returned. It also sets any extra response headers.
Types ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a simple implementation of Data.
func (Value) ETag ¶ added in v0.9.0
ETag computes and sets the entity tag header on the response using some hash value. This is used for efficient conditional requests, possibly avoiding network traffic. The parameter fn evaluates the hash lazily based on the content of this Data (which may also be evaluated lazily).
func (Value) Expires ¶ added in v0.9.0
Expires sets the time at which the response becomes stale. MaxAge takes precedence.
func (Value) LastModified ¶ added in v0.9.0
LastModified sets the time at which the content was last modified. This allows for conditional requests, possibly avoiding network traffic. ETag takes precedence.
func (Value) MaxAge ¶ added in v0.9.0
MaxAge sets the max-age header on the response. This is used to allow caches to avoid repeating the request until the max age has expired, after which time the resource is considered stale.
func (Value) NoCache ¶ added in v0.9.0
NoCache sets cache control headers to prevent the response being cached.
func (Value) With ¶
With returns a copy of v with extra headers attached. These are passed in as key+value pairs. The header names should be in normal form, e.g. "Last-Modified" instead of "last-modified", but this is not mandatory. The values are simple strings, numbers etc. Or they can be func(interface{}) string, in which case they will be called using the result of Content.