Documentation
¶
Overview ¶
Package webtools is a collection of helper types, functions, abstractions, and additional packages for building standalone websites. In particular, sites that make use of oauth based sessions for user identity and authentication.
Index ¶
- func CreateURL(origin, path string, params map[string]string) *url.URL
- func GetDomain(s string) string
- func Sanitize(s string) string
- func SetBasicAuth(r *http.Request, username, password string)
- func SetCacheControl(w http.ResponseWriter, ttl time.Duration)
- func SetContentType(w http.ResponseWriter, filetype MIMEType)
- func SetRobotsTag(w http.ResponseWriter, instruction RobotIndex)
- type MIMEType
- type Origin
- type RobotIndex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateURL ¶
CreateURL creates a *url.URL from the given origin, path, and request parameters that has been properly encoded and formatted.
resource url must be valid; an invalid url will panic.
func GetDomain ¶ added in v0.2.2
GetDomain extracts the domain name from a given url s.
If s is not a valid url, the empty string is returned.
func Sanitize ¶ added in v0.6.0
Sanitize purges known tracker URL parameters.
If s fails to parse as a url, the original string is returned.
func SetBasicAuth ¶
SetBasicAuth sets the Authorization header on r, using the given username and password.
NOTE: if either username or password is empty, no header is set.
func SetCacheControl ¶
func SetCacheControl(w http.ResponseWriter, ttl time.Duration)
SetCacheControl sets a private Cache-Control headers on w with the given duration, rounded to seconds.
func SetContentType ¶
func SetContentType(w http.ResponseWriter, filetype MIMEType)
SetContentType sets the Content-Type header on w to the givien MIME compatible content type string.
func SetRobotsTag ¶
func SetRobotsTag(w http.ResponseWriter, instruction RobotIndex)
SetRobotsTag to a crawl control value (e.g. noindex)
Types ¶
type MIMEType ¶
type MIMEType string
MIMEType are correct identifier strings for various MIME types.
Consider using one of the pre-defined types.
const ( ContentTypeText MIMEType = "text/plain; charset=utf8" ContentTypeHTML MIMEType = "text/html; charset=utf-8" ContentTypeXML MIMEType = "text/xml; charset=utf8" ContentTypeRSS MIMEType = "application/rss+xml; charset=utf8" ContentTypeJSON MIMEType = "application/json" // implicit utf8 charset )
type Origin ¶
type Origin struct {
// about the request
Method string
Host string
UserAgent useragent.UserAgent
// about the requesting entity
Remote string
Forward string
Reference string
}
Origin contins request origination context from parsing request headers.
func Origins ¶
Origins parses the request headers to get information about the origins of the request, including ...
- Method - Host - Forwarder - Referer - User-Agent
func (*Origin) Anchor ¶ added in v0.2.1
Anchor returns a parsed version of the Referer headers, including the domain and path without the protocol or query.
type RobotIndex ¶
type RobotIndex string
RobotIndex are correct sentinel values for indicating whether a page should be indexed, as set in the X-Robots-Tag HTTP response header.
Consider using one of the pre-defined types.
const ( RobotsNoIndex RobotIndex = "noindex" RobotsYesIndex RobotIndex = "all" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package expcache provides an in-memory expiry cache.
|
Package expcache provides an in-memory expiry cache. |