Documentation ¶
Index ¶
- Constants
- func ASCIIHeader(key, value, padChar string, child http.Handler) http.Handler
- func CanonicalHost(url string, options int, childHandler http.Handler) http.Handler
- func ContentType(logger *log.Logger, basePath string) http.Handler
- func DirSplit(logger *log.Logger, basepath string, done <-chan struct{}, ...) http.Handler
- func Expires(maxAge time.Duration, child http.Handler) http.Handler
- func ExpiresRange(min, max time.Duration, child http.Handler) http.Handler
- func Header(name, msg string, handler http.Handler) http.Handler
- func Index(logger *log.Logger, basepath string, done <-chan struct{}, ...) http.Handler
- func Internal(logger *log.Logger, fs http.FileSystem) http.Handler
- func ResponseCode(code int, msg string, args ...interface{}) http.Handler
- func Split(root, more http.Handler) http.Handler
- func Success(msg string) http.Handler
- func ThumbCache(logger *log.Logger, targetWidth, targetHeight int, cacheSize int64, ...) http.Handler
- func Thumbnail(logger *log.Logger, targetWidth, targetHeight int, ...) http.Handler
- type IndexData
- type MethodHandler
- type RedirectURIHandler
Constants ¶
const ( ForceHTTP = 1 << iota // force http as the redirect target ForceHTTPS // force https as the redirect target ForceHost // force the given hostname as the redirect target ForcePort // force a given port for the redirect target ForceTemporary // Use a 302 for the redirect )
These constants are to be used with the Canocial Host Handler.
const GolangGopherASCII = `` /* 3969-byte string literal not displayed */
GolangGopherASCII is a ascii drawing of a golang gopher for use in ASCIIHeader()
const Megabyte int = 1 << 20
Variables ¶
This section is empty.
Functions ¶
func ASCIIHeader ¶
ASCIIHeader adds a multiline header to the response - a header for each line. It is used to add ascii art to the header of a response.
Both key and value can be a multiline string = and will be broken up as needed. Key will be repeated for the duration of value for each header line.
You need to make sure both key and value have a consistent length after white space trimming on each line, as HTTP will do that anyway. If you don't, this will split on newlines, trim spaces, then right pad the key with underscores so things line up anyway.
func CanonicalHost ¶
CanonicalHost returns a http.Handler that redirects to the canocial host based on certain options. 0 may be passed for options if so desired, or provided bits can be forced on the client with a redirect.
func ContentType ¶
ContentType serves a given file back to the requester, and determines content type by algorithm only. It does not use the file's extension to determine the content type.
func DirSplit ¶
func DirSplit(logger *log.Logger, basepath string, done <-chan struct{}, folder, other http.Handler) http.Handler
DirSplit takes two child handlers - one for the directories, one for the other locations. It then watches a directory - and sub directories - and any request that would match a directory relative to that path is routed to the handler for directories. All other requests are routed to the other handler.
func Index ¶
func Index(logger *log.Logger, basepath string, done <-chan struct{}, templ *template.Template) http.Handler
Index lists all files in a directory, and passes them to template execution to build a directory listing. It also creates a list of directories and passes those - but symlinks to directories are not handled.
func Internal ¶
Internal serves a static, in memory filesystem. The filesystem to be served should have been generated with embed or similar..
Note - this is likely a duplicate of http.FileServer. It will likely be removed.
func ResponseCode ¶
ResponseCode responds with an error to any request with the error code and message provided.
func Success ¶
Success returns a handler that responds to every request with a 200 and always the same message.
func ThumbCache ¶
func ThumbCache(logger *log.Logger, targetWidth, targetHeight int, cacheSize int64, rawImageDirectory, cacheName, thumbnailExtension string) http.Handler
ThumbCache returns a handler that serves thumbnails from GroupCache. Thumbnails are generated when needed by GroupCache.
func Thumbnail ¶
func Thumbnail(logger *log.Logger, targetWidth, targetHeight int, rawImageDirectory, thumbnailDirectory, thumbnailExtension string) http.Handler
Thumbnail returns a handler that generates a thumbnail of the given size of each image, stores it in the specified location, and serves back the thumbnails upon request. Thumbnails are generated when needed. File caching is used to decrease thumbnail generation.
Types ¶
type MethodHandler ¶
MethodHandler splits requests to the Handler across the Method map.
func (MethodHandler) ServeHTTP ¶
func (h MethodHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP makes MethodHandler a http.Handler.
type RedirectURIHandler ¶
RedirectURIHandler creates a handler that responds with a redirect to another domain. The URI is preserved, optionally with a prefix added. https is included or not, based on the value of TLS.
func (*RedirectURIHandler) ServeHTTP ¶
func (rh *RedirectURIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP makes RedirectURIHandler a http.Handler.