Documentation
¶
Index ¶
- Constants
- func CanonicalURLPath(p string) string
- func DescribeBytes(size int64) string
- func ExtractKeywords(data []byte, keywordsToLookFor []string) ([]byte, map[string][]byte)
- func ExtractLocalImagePaths(html string) []string
- func FilterIntoGroups(bytelines [][]byte, filterfunc func([]byte) bool) ([][]byte, [][]byte)
- func GetDomain(req *http.Request) string
- func GetFilenames(dirname string) []string
- func GetHost(req *http.Request) string
- func HostPortToURL(addr string) string
- func Infostring(functionName string, args []string) string
- func IsIPv6(host string) bool
- func IsLocalIP(host string) bool
- func JoinHostPort(host, colonPort string) string
- func ResolvesWithinDir(root, p string) bool
- func URL2filename(dirname, urlpath string) string
- func WithinDir(root, p string) bool
- func WriteStatus(sb *strings.Builder, title string, flags map[string]bool)
- type Node
- type PrefixMatch
Constants ¶
const ( // Pathsep is the path separator for the current platform Pathsep = string(filepath.Separator) // KiB is a kilobyte (kibibyte) KiB = 1024 // MiB is a megabyte (mibibyte) MiB = 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func CanonicalURLPath ¶ added in v1.17.11
CanonicalURLPath resolves ".." and "." elements, collapses repeated slashes and adds a leading slash. A trailing slash is kept, since it tells directories and files apart.
func DescribeBytes ¶
DescribeBytes converts bytes to KiB or MiB. Returns a string.
func ExtractKeywords ¶
ExtractKeywords takes a source file as `data` and a list of keywords to
- look for. Lines without keywords are returned, together with a map
- from keywords to []bytes from the source `data`. *
- The keywords in the data must be on the form "keyword: value",
- and can be within single-line HTML comments (<-- ... -->).
func ExtractLocalImagePaths ¶ added in v1.15.5
ExtractLocalImagePaths can be used to find local image filenames that are included in the given HTML
func FilterIntoGroups ¶
FilterIntoGroups filters []byte slices into two groups, depending on the given filter function
func GetDomain ¶
GetDomain returns the host/domain of a request, handling both IPv4 and IPv6. The loopback hosts 127.0.0.1 and ::1, and also the IP addresses of this machine, are collapsed to "localhost", so that a single localhost/ document root serves them all.
func GetFilenames ¶
GetFilenames retrieves a list of filenames from a given directory name (that must exist)
func GetHost ¶ added in v1.17.10
GetHost returns the host of a request, handling both IPv4 and IPv6. Unlike GetDomain, it does not collapse loopback addresses, so URLs built from it stay same-origin with the request.
func HostPortToURL ¶ added in v1.17.6
HostPortToURL converts an address to a URL-friendly host:port string. Converts ":8080" to "localhost:8080" and ensures IPv6 addresses have brackets.
func Infostring ¶
Infostring builds up a string on the form "functionname(arg1, arg2, arg3)"
func IsLocalIP ¶ added in v1.17.12
IsLocalIP checks if the given host is a loopback address or one of the IP addresses of this machine
func JoinHostPort ¶ added in v1.17.6
JoinHostPort combines a host and a colonPort (like ":8080") into an address. Handles IPv6 by adding brackets as needed. If host is empty, returns colonPort as-is.
func ResolvesWithinDir ¶ added in v1.17.12
ResolvesWithinDir reports whether p, after following any symlinks, is still within root. Paths that do not exist are reported as within root, since there is nothing there to be served.
func URL2filename ¶
URL2filename translates a given URL path to a probable full filename. URL paths that lead outside of dirname result in dirname itself.
Types ¶
type PrefixMatch ¶ added in v1.15.0
type PrefixMatch struct {
// contains filtered or unexported fields
}
PrefixMatch tests whether a string starts with any of a set of prefixes.
func (*PrefixMatch) Build ¶ added in v1.15.0
func (pm *PrefixMatch) Build(prefixes []string)
Build constructs the prefix trie from the given list of prefixes.
func (*PrefixMatch) Match ¶ added in v1.15.0
func (pm *PrefixMatch) Match(str string) []string
Match returns the prefixes from the trie that match the start of str.