util

package
v6.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: Apache-2.0 Imports: 20 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("resource not found")

ErrNotFound is used to explicitly signal error cases, where a resource can not be found (404 HTTP status code).

Functions

func CloneMap added in v6.0.3

func CloneMap[M ~map[K]V, K comparable, V any](m M) M

CloneMap returns a copy of m. This is a shallow clone: the new keys and values are set using ordinary assignment.

func DeepCopy

func DeepCopy(src, dest any) error

DeepCopy copies src to dest by using encoding/gob so its not that fast.

func DownloadFileHash

func DownloadFileHash(ctx context.Context, httpClient *http.Client, useragent string, progress func(progress ioprogress.ProgressData), canceler *cancel.HTTPRequestCanceller, filename string, url string, hash string, hashFunc hash.Hash, target io.WriteSeeker) (int64, error)

func IsFalse

func IsFalse(value string) bool

IsFalse returns true if value is "false", "0", "no" or "off" (case insensitive).

func IsFalseOrEmpty

func IsFalseOrEmpty(value string) bool

IsFalseOrEmpty returns true if value is empty or if IsFalse() returns true.

func IsNoneOrEmpty added in v6.9.0

func IsNoneOrEmpty(value string) bool

IsNoneOrEmpty returns true if value is empty or a "none" value.

func IsTrue

func IsTrue(value string) bool

IsTrue returns true if value is "true", "1", "yes" or "on" (case insensitive).

func IsTrueOrEmpty

func IsTrueOrEmpty(value string) bool

IsTrueOrEmpty returns true if value is empty or if IsTrue() returns true.

func OpenBrowser added in v6.0.3

func OpenBrowser(url string) error

OpenBrowser opens the provided URL in the default web browser.

func ParseUint32Range

func ParseUint32Range(value string) (uint32, uint32, error)

ParseUint32Range parses a uint32 range in the form "number" or "start-end". Returns the start number and the size of the range.

func PathExists

func PathExists(name string) bool

func PathIsWritable

func PathIsWritable(path string) bool

func SplitNTrimSpace

func SplitNTrimSpace(s string, sep string, n int, nilIfEmpty bool) []string

SplitNTrimSpace returns result of strings.SplitN() and then strings.TrimSpace() on each element. Accepts nilIfEmpty argument which if true, will return nil slice if s is empty (after trimming space).

func StringHasPrefix

func StringHasPrefix(value string, prefixes ...string) bool

StringHasPrefix returns true if value has one of the supplied prefixes.

func StringPrefixInSlice

func StringPrefixInSlice(key string, list []string) bool

StringPrefixInSlice returns true if any element in the list has the given prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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