utils

package
v1.17.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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 DescribeBytes

func DescribeBytes(size int64) string

DescribeBytes converts bytes to KiB or MiB. Returns a string.

func ExtractKeywords

func ExtractKeywords(data []byte, keywordsToLookFor []string) ([]byte, map[string][]byte)

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

func ExtractLocalImagePaths(html string) []string

ExtractLocalImagePaths can be used to find local image filenames that are included in the given HTML

func FilterIntoGroups

func FilterIntoGroups(bytelines [][]byte, filterfunc func([]byte) bool) ([][]byte, [][]byte)

FilterIntoGroups filters []byte slices into two groups, depending on the given filter function

func GetDomain

func GetDomain(req *http.Request) string

GetDomain returns the host/domain of a request, handling both IPv4 and IPv6

func GetFilenames

func GetFilenames(dirname string) []string

GetFilenames retrieves a list of filenames from a given directory name (that must exist)

func HostPortToURL added in v1.17.6

func HostPortToURL(addr string) string

HostPortToURL converts an address to a URL-friendly host:port string. Converts ":8080" to "localhost:8080" and ensures IPv6 addresses have brackets.

func Infostring

func Infostring(functionName string, args []string) string

Infostring builds up a string on the form "functionname(arg1, arg2, arg3)"

func IsIPv6 added in v1.17.6

func IsIPv6(host string) bool

IsIPv6 checks if the given string is an IPv6 address

func JoinHostPort added in v1.17.6

func JoinHostPort(host, colonPort string) string

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 URL2filename

func URL2filename(dirname, urlpath string) string

URL2filename translates a given URL path to a probable full filename

func WriteStatus

func WriteStatus(sb *strings.Builder, title string, flags map[string]bool)

WriteStatus writes status messages to a string Builder The flags argument contains the flag names, and if they are enabled or not

Types

type Node added in v1.15.0

type Node struct {
	Children   map[rune]*Node
	IsTerminal bool
}

type PrefixMatch added in v1.15.0

type PrefixMatch struct {
	// contains filtered or unexported fields
}

func (*PrefixMatch) Build added in v1.15.0

func (pm *PrefixMatch) Build(prefixes []string)

func (*PrefixMatch) Match added in v1.15.0

func (pm *PrefixMatch) Match(str string) []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL