util

package
v0.0.0-...-d7e1125 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 21 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnnotationsToBeSkipped = []string{
	"kubectl.kubernetes.io/last-applied-configuration",
}

AnnotationsToBeSkipped kubectl service annotation that we'd like to skip

Functions

func BuildPrometheusLabel

func BuildPrometheusLabel(label string) string

func BuildPrometheusLabels

func BuildPrometheusLabels(labels ...string) []string

func BuildPrometheusMetricName

func BuildPrometheusMetricName(name string) string

func BuildRFC1035Label

func BuildRFC1035Label(str string) (string, bool)

func BuildShellEnvVarName

func BuildShellEnvVarName(str string) (string, bool)

func CastToSliceOfStrings

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

CastToSliceOfStrings makes slice of strings from map

func ConcatSlices

func ConcatSlices[T any](slices [][]T) []T

func ContextError

func ContextError(ctx context.Context) error

ContextError is a one-word syntactic sugar to check what error is reported by the context.

func CopyMap

func CopyMap(src map[string]string) map[string]string

CopyMap creates a copy of the given map by copying over key by key. It doesn't perform a deep-copy.

func CopyMapExclude

func CopyMapExclude(src map[string]string, exceptKeys ...string) map[string]string

CopyMapExclude creates a copy of the given map but will exclude the given set of keys.

func CopyMapFilter

func CopyMapFilter(src map[string]string, include, exclude []string) map[string]string

CopyMapFilter copies maps with keys filtering. Keys specified in 'include' are included, keys specified in 'exclude' are excluded. However, 'include' keys are applied only in case 'include' list is not empty.

func CopyMapInclude

func CopyMapInclude(src map[string]string, keys ...string) map[string]string

CopyMapInclude creates a copy of the given map but will include the given set of keys only. However, keys are applied only in case list is not empty. In case of an empty list, no filtering is performed and all keys are copied.

func CreateStringID

func CreateStringID(str string, maxHashLen int) string

CreateStringID creates HEX hash ID out of a string. In case maxHashLen == 0 the whole hash is returned

func DecBottomed

func DecBottomed(start, dec, bottom int) int

func Dump

func Dump(obj interface{}) string

Dump dumps object into string with repeatable order

func ErrIsNotCanceled

func ErrIsNotCanceled(err error) bool

ErrIsNotCanceled checks whether specified error is either not an error is is not a context.Canceled

func ExtToLower

func ExtToLower(file string) string

ExtToLower fetches and lower-cases file extension. With dot, as '.xml'

func Fingerprint

func Fingerprint(obj interface{}) string

Fingerprint creates object's fingerprint

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{})

Fprintf suppresses warning for unused returns of fmt.Fprintf()

func HasEnvVar

func HasEnvVar(haystack []core.EnvVar, needle core.EnvVar) bool

HasEnvVar checks whether a haystack has a needle

func HashIntoInt

func HashIntoInt(b []byte) int

HashIntoInt hashes bytes and returns int version of the hash

func HashIntoIntTopped

func HashIntoIntTopped(b []byte, top int) int

HashIntoIntTopped hashes bytes and return int version of the ash topped with top

func HashIntoString

func HashIntoString(b []byte) string

HashIntoString hashes bytes and returns string version of the hash

func Iline

func Iline(w io.Writer, indent int, format string, a ...interface{})

Iline writes indented line with \n into provided io.Writer

func InArray

func InArray(needle string, haystack []string) bool

InArray checks whether the needle is in the haystack

func InArrayWithRegexp

func InArrayWithRegexp(needle string, haystack []string) bool

InArrayWithRegexp checks whether the needle can be matched by haystack

func IncTopped

func IncTopped(start, inc, top int) int

func IncludeNonEmpty

func IncludeNonEmpty(dst map[string]string, key, src string)

IncludeNonEmpty inserts (and overwrites) data into map object using specified key, if not empty value provided

func IntersectStringArrays

func IntersectStringArrays(a []string, b []string) (res []string)

IntersectStringArrays intersects arrays `a` and `b`

func IsAnnotationToBeSkipped

func IsAnnotationToBeSkipped(annotation string) bool

IsAnnotationToBeSkipped checks whether an annotation should be skipped

func IsContextDone

func IsContextDone(ctx context.Context) bool

IsContextDone is a non-blocking one-word syntactic sugar to check whether context is done. Convenient to be used as

if IsContextDone(ctx) {
  ... do something ...
}

func IsDirOk

func IsDirOk(path string) bool

IsDirOk returns whether the given path exists and is a dir

func IsShellEnvVarName

func IsShellEnvVarName(value string) bool

IsShellEnvVarName tests for a string that conforms to the definition of a shell ENV VAR name

func IsValidDNS1035Label

func IsValidDNS1035Label(value string) bool

IsValidDNS1035Label tests for a string that conforms to the definition of a label in DNS (RFC 1035).

func IsValidPrometheusLabel

func IsValidPrometheusLabel(value string) bool

IsValidPrometheusLabel tests for a string that conforms to the definition of a label in Prometheus

func IsValidPrometheusLabelValue

func IsValidPrometheusLabelValue(value string) bool

func IsValidPrometheusMetricName

func IsValidPrometheusMetricName(value string) bool

IsValidPrometheusMetricName tests for a string that conforms to the definition of a metric in Prometheus

func ListSkippedAnnotations

func ListSkippedAnnotations() []string

ListSkippedAnnotations provides list of annotations that should be skipped

func Map2String

func Map2String(name string, m map[string]string) string

Map2String returns named map[string]string mas as a string

func MapDeleteKeys

func MapDeleteKeys(base map[string]string, keys ...string) map[string]string

MapDeleteKeys deletes multiple keys from the map

func MapGetSortedKeys

func MapGetSortedKeys(m map[string]string) (keys []string)

func MapGetSortedKeysAndValues

func MapGetSortedKeysAndValues(m map[string]string) (keys []string, values []string)

func MapHasKeys

func MapHasKeys(m map[string]string, keys ...string) bool

MapHasKeys checks whether map has all keys from specified list

func MapMigrate

func MapMigrate(cur, new, old map[string]string) map[string]string

func MergeEnvVars

func MergeEnvVars(to []core.EnvVar, from ...core.EnvVar) []core.EnvVar

MergeEnvVars appends to `to` elements from `from` which are not found in `to`

func MergeStringArrays

func MergeStringArrays(dst []string, src []string) []string

MergeStringArrays appends into dst items from src that are not present in src. src items are being deduplicated

func MergeStringMapsOverwrite

func MergeStringMapsOverwrite(dst, src map[string]string, keys ...string) map[string]string

MergeStringMapsOverwrite inserts (and overwrites) data into dst map object from src

func MergeStringMapsPreserve

func MergeStringMapsPreserve(dst, src map[string]string, keys ...string) map[string]string

MergeStringMapsPreserve inserts (and preserved existing) data into dst map object from src

func MessageDiffItemString

func MessageDiffItemString(bannerForDiff, bannerForNoDiff, defaultPath string, items map[*messagediff.Path]interface{}) (str string)

MessageDiffItemString stringifies one map[*messagediff.Path]interface{} item

func MessageDiffString

func MessageDiffString(diff *messagediff.Diff, equal bool) string

MessageDiffString stringifies message diff

func NamespaceName

func NamespaceName(meta meta.Object) (string, string)

NamespaceName returns namespace and anme from the meta

func NamespaceNameString

func NamespaceNameString(meta meta.Object) string

NamespaceNameString returns namespace and name as one string

func NamespacedName

func NamespacedName(obj meta.Object) types.NamespacedName

NamespacedName returns NamespacedName from obj

func NonEmpty

func NonEmpty(slice []string) (nonEmpty []string)

func Prefix

func Prefix(slice []string, prefix string) (res []string)

func PreparePath

func PreparePath(path *string, basePath, defaultRelativePath string)

PreparePath - prepares path absolute/relative with default relative value

func RandString

func RandString(length int) string

RandString generates random string of specified length

func RandStringRange

func RandStringRange(minLength, maxLength int) string

RandStringRange specifies random string with length in specified range

func ReadFilesIntoMap

func ReadFilesIntoMap(path string, isOurFile func(string) bool) map[string]string

ReadFilesIntoMap reads config files from specified path into "file name->file content" map path - folder where to look for files isOurFile - accepts path to file return bool whether this file should be read

func ReasonableDuration

func ReasonableDuration(durations ...time.Duration) time.Duration

ReasonableDuration finds first duration > 0 or returns 0 in case no durations provided

func RelativeToBasePath

func RelativeToBasePath(basePath, relativePath string) string

RelativeToBasePath returns absolute path relative to base

func RemoveFromArray

func RemoveFromArray(needle string, haystack []string) []string

RemoveFromArray removes the needle from the haystack

func Slice2String

func Slice2String(name string, slice []string) string

Slice2String returns named slice as a string

func StringHead

func StringHead(str string, maxHeadLen int) string

StringHead returns beginning of the string of requested length

func StringSliceContains

func StringSliceContains(haystack []string, needle string) bool

StringSliceContains implements contain method for string slice

func SubtractStringMaps

func SubtractStringMaps(base, delta map[string]string) map[string]string

SubtractStringMaps subtracts "delta" from "base" by keys

func Unique

func Unique(slice []string) (unique []string)

func Unzip

func Unzip(slice [][]string) ([]string, []string)

Unzip makes two 1-value columns (slices) out of one 2-value column (slice)

func WaitContextDoneOrTimeout

func WaitContextDoneOrTimeout(ctx context.Context, timeout time.Duration) bool

WaitContextDoneOrTimeout waits either for ctx to be done or specified timeout returns true in case ctx is Done or false in case timeout reached

func WaitContextDoneUntil

func WaitContextDoneUntil(ctx context.Context, t time.Time) bool

WaitContextDoneUntil waits either for ctx to be done or specified moment in time reached returns true in case ctx is Done or false in case specified time reached

Types

type MapReplacer

type MapReplacer struct {
	*strings.Replacer
}

MapReplacer replaces a list of strings with replacements on a map.

func NewMapReplacer

func NewMapReplacer(r *strings.Replacer) *MapReplacer

NewMapReplacer creates new MapReplacer

func (*MapReplacer) Replace

func (r *MapReplacer) Replace(m map[string]string) map[string]string

Replace returns a copy of m with all replacements performed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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