helper

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MPL-2.0 Imports: 11 Imported by: 980

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHCLKeys added in v0.7.0

func CheckHCLKeys(node ast.Node, valid []string) error

func CheckNamespaceScope added in v0.12.2

func CheckNamespaceScope(provided string, requested []string) []string

CheckNamespaceScope ensures that the provided namespace is equal to or a parent of the requested namespaces. Returns requested namespaces which are not equal to or a child of the provided namespace.

func CleanEnvVar added in v0.5.5

func CleanEnvVar(s string, r byte) string

CleanEnvVar replaces all occurrences of illegal characters in an environment variable with the specified byte.

func CleanFilename added in v1.0.0

func CleanFilename(filename string, replace string) string

CleanFilename replaces invalid characters in filename

func CleanFilenameASCIIOnly added in v1.0.0

func CleanFilenameASCIIOnly(filename string, replace string) string

CleanFilenameASCIIOnly replaces invalid and non-ASCII characters in filename

func CleanFilenameStrict added in v1.0.0

func CleanFilenameStrict(filename string, replace string) string

CleanFilenameStrict replaces invalid and punctuation characters in filename

func CompareMapStringString added in v0.9.0

func CompareMapStringString(a, b map[string]string) bool

CompareMapStringString returns true if the maps are equivalent. A nil and empty map are considered not equal.

func CompareSliceSetString added in v0.10.0

func CompareSliceSetString(a, b []string) bool

CompareSliceSetString returns true if the slices contain the same strings. Order is ignored. The slice may be copied but is never altered. The slice is assumed to be a set. Multiple instances of an entry are treated the same as a single instance.

func CompareTimePtrs added in v0.12.4

func CompareTimePtrs(a, b *time.Duration) bool

CompareTimePtrs return true if a is the same as b.

func CopyMap added in v1.2.11

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

CopyMap creates a copy of m. Struct values are not deep copies.

If m is nil or contains no elements, the return value is nil.

func CopyMapStringFloat64

func CopyMapStringFloat64(m map[string]float64) map[string]float64

CopyMapStringFloat64 creates a copy of m.

Deprecated; use CopyMap instead.

func CopyMapStringInt

func CopyMapStringInt(m map[string]int) map[string]int

func CopyMapStringInterface added in v0.12.4

func CopyMapStringInterface(m map[string]interface{}) map[string]interface{}

CopyMapStringInterface creates a copy of m.

Deprecated; use CopyMap instead.

func CopyMapStringSliceString added in v0.6.1

func CopyMapStringSliceString(m map[string][]string) map[string][]string

CopyMapStringSliceString copies a map of strings to string slices such as http.Header

func CopyMapStringString

func CopyMapStringString(m map[string]string) map[string]string

CopyMapStringString creates a copy of m.

Deprecated; use CopyMap instead.

func CopyMapStringStruct added in v0.6.1

func CopyMapStringStruct(m map[string]struct{}) map[string]struct{}

CopyMapStringStruct creates a copy of m.

Deprecated; use CopyMap instead.

func CopySliceInt

func CopySliceInt(s []int) []int

CopySliceInt creates a copy of s.

Deprecated; use slices.Clone instead.

func CopySliceString

func CopySliceString(s []string) []string

CopySliceString creates a copy of s.

Deprecated; use slices.Clone instead.

func ElementsEquals added in v1.2.11

func ElementsEquals[T EqualsFunc[T]](a, b []T) bool

ElementsEquals returns true if slices a and b contain the same elements (in no particular order) using the Equals function defined on their type for comparison.

func HashUUID added in v0.6.0

func HashUUID(input string) (output string, hashed bool)

HashUUID takes an input UUID and returns a hashed version of the UUID to ensure it is well distributed.

func IsMethodHTTP added in v1.2.11

func IsMethodHTTP(s string) bool

IsMethodHTTP returns whether s is a known HTTP method, ignoring case.

func IsUUID added in v0.5.5

func IsUUID(str string) bool

IsUUID returns true if the given string is a valid UUID.

func IsValidInterpVariable added in v0.9.0

func IsValidInterpVariable(str string) bool

IsValidInterpVariable returns true if a valid dotted variable names for interpolation. The string must begin with one or more non-dot characters which may be followed by sequences containing a dot followed by a one or more non-dot characters.

func MapStringStringSliceValueSet

func MapStringStringSliceValueSet(m map[string][]string) []string

MapStringStringSliceValueSet returns the set of values in a map[string][]string

func Max added in v1.2.11

func Max[T constraints.Ordered](a, b T) T

Max returns the maximum of a and b.

func Min added in v1.2.11

func Min[T constraints.Ordered](a, b T) T

Min returns the minimum of a and b.

func PathEscapesSandbox added in v0.10.7

func PathEscapesSandbox(sandboxDir, path string) bool

PathEscapesSandbox returns whether previously cleaned path inside the sandbox directory (typically this will be the allocation directory) escapes.

func RemoveEqualFold added in v0.11.0

func RemoveEqualFold(xs *[]string, search string)

RemoveEqualFold removes the first string that EqualFold matches. It updates xs in place

func SliceSetDisjoint

func SliceSetDisjoint(first, second []string) (bool, []string)

func SliceStringContains added in v0.12.2

func SliceStringContains(list []string, item string) bool

SliceStringContains returns whether item exists at least once in list.

func SliceStringHasPrefix added in v1.0.13

func SliceStringHasPrefix(list []string, prefix string) bool

SliceStringHasPrefix returns true if any string in list starts with prefix

func SliceStringIsSubset

func SliceStringIsSubset(larger, smaller []string) (bool, []string)

SliceStringIsSubset returns whether the smaller set of strings is a subset of the larger. If the smaller slice is not a subset, the offending elements are returned.

func SliceStringToSet

func SliceStringToSet(s []string) map[string]struct{}

func StringHasPrefixInSlice added in v1.0.13

func StringHasPrefixInSlice(s string, prefixes []string) bool

StringHasPrefixInSlice returns true if string starts with any prefix in list

func UnusedKeys added in v0.11.0

func UnusedKeys(obj interface{}) error

UnusedKeys returns a pretty-printed error if any `hcl:",unusedKeys"` is not empty

Types

type EqualsFunc added in v1.2.11

type EqualsFunc[A any] interface {
	Equals(A) bool
}

EqualsFunc represents a type implementing the Equals method.

type StopFunc added in v1.1.13

type StopFunc func()

StopFunc is used to stop a time.Timer created with NewSafeTimer

func NewSafeTimer added in v1.1.13

func NewSafeTimer(duration time.Duration) (*time.Timer, StopFunc)

NewSafeTimer creates a time.Timer but does not panic if duration is <= 0.

Using a time.Timer is recommended instead of time.After when it is necessary to avoid leaking goroutines (e.g. in a select inside a loop).

Returns the time.Timer and also a StopFunc, forcing the caller to deal with stopping the time.Timer to avoid leaking a goroutine.

Directories

Path Synopsis
BOLTdd contains a wrapper around BoltDB to deduplicate writes and encode values using mgspack.
BOLTdd contains a wrapper around BoltDB to deduplicate writes and encode values using mgspack.
constraints
semver
semver is a Semver Constraints package copied from github.com/hashicorp/go-version @ 2046c9d0f0b03c779670f5186a2a4b2c85493a71
semver is a Semver Constraints package copied from github.com/hashicorp/go-version @ 2046c9d0f0b03c779670f5186a2a4b2c85493a71
Package envoy provides a high level view of the variables that go into selecting an envoy version.
Package envoy provides a high level view of the variables that go into selecting an envoy version.
Package exptime provides a generalized exponential backoff retry implementation.
Package exptime provides a generalized exponential backoff retry implementation.
Copied from github.com/hashicorp/consul/sdk/freeport
Copied from github.com/hashicorp/consul/sdk/freeport
grpc-middleware
Package noxssrw (No XSS ResponseWriter) behaves like the Go standard library's ResponseWriter by detecting the Content-Type of a response if it has not been explicitly set.
Package noxssrw (No XSS ResponseWriter) behaves like the Go standard library's ResponseWriter by detecting the Content-Type of a response if it has not been explicitly set.
pluginutils
catalog
Package catalog is used to register internal plugins such that they can be loaded.
Package catalog is used to register internal plugins such that they can be loaded.
Package pointer provides helper functions related to Go pointers.
Package pointer provides helper functions related to Go pointers.
Code generated by go generate; DO NOT EDIT.
Code generated by go generate; DO NOT EDIT.
The archive utilities manage the internal format of a snapshot, which is a tar file with the following contents:
The archive utilities manage the internal format of a snapshot, which is a tar file with the following contents:
Package testlog creates a *log.Logger backed by *testing.T to ease logging in tests.
Package testlog creates a *log.Logger backed by *testing.T to ease logging in tests.
Package testtask implements a portable set of commands useful as stand-ins for user tasks.
Package testtask implements a portable set of commands useful as stand-ins for user tasks.

Jump to

Keyboard shortcuts

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