collections

package
v1.29.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v1.12.0

func Append[T any](slices ...[]T) []T

Append concatenates multiple slices of strings into a single slice.

func Contains added in v1.5.1

func Contains[T comparable](a []T, x T) bool

Contains tells whether a contains x.

func Dedup added in v1.10.0

func Dedup[T comparable](arr []T) []T

func DeleteEmptyStrings added in v1.10.0

func DeleteEmptyStrings(s []string) []string

func Find added in v1.5.1

func Find(a []string, x string) int

Find returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func IniToMap

func IniToMap(path string) map[string]string

IniToMap takes the path to an INI formatted file and transforms it into a map

func KeyValueSliceToMap added in v1.6.3

func KeyValueSliceToMap(in []string) map[string]string

KeyValueSliceToMap takes in a list of strings in a=b format and returns a map from it.

Any string that's not in a=b format will be ignored.

func MapKeys added in v1.11.0

func MapKeys[K comparable, T any](m map[K]T) []K

func MapToIni

func MapToIni(Map map[string]string) string

MapToIni takes a map and converts it into an INI formatted string

func MatchItems added in v1.6.4

func MatchItems(item string, items ...string) bool

matchItems returns true if any of the items in the list match the item. negative matches are supported by prefixing the item with a "!". * matches everything to match prefix and suffix use "*" accordingly.

func MergeMap added in v1.6.3

func MergeMap[T1 comparable, T2 any](a, b map[T1]T2) map[T1]T2

MergeMap will merge map b into a. On key collision, map b takes precedence.

func MergeStructs added in v1.10.0

func MergeStructs[T any](base, patch T) (T, error)

MergeStructs merges two structs where patch is applied on top of base

func ReplaceAllInSlice

func ReplaceAllInSlice(a []string, find string, replacement string) (replaced []string)

ReplaceAllInSlice runs strings.Replace on all elements in a slice and returns the result

func SelectorToMap added in v1.22.0

func SelectorToMap(selector string) (matchLabels map[string]string)

SelectorToMap returns a map from a selector string. i.e. "a=b,c=d" -> {"a": "b", "c": "d"}

func SortedMap added in v1.22.0

func SortedMap(m map[string]string) string

SortedMap takes a map and returns a sorted key value string i.e. {"a": "b", "c": "d"} -> "a=b,c=d"

func SplitAllInSlice

func SplitAllInSlice(a []string, split string, index int) (replaced []string)

SplitAllInSlice runs strings.Split on all elements in a slice and returns the results at the given index

func StructToIni

func StructToIni(s interface{}) string

StructToIni takes an object and serializes it's fields in INI format

func StructToJSON added in v1.8.0

func StructToJSON(v any) (string, error)

StructToJSON takes an object and returns its json form

func StructToMap

func StructToMap(s interface{}) map[string]interface{}

StructToMap takes an object and returns all it's field in a map

func ToBase64Map

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

ToBase64Map converts a map[string]interface{} to a map[string]string by converting []byte to base64

func ToByteMap

func ToByteMap(m map[string]interface{}) map[string][]byte

ToByteMap converts a map[string]interface{} to a map[string]string by converting []byte to base64

func ToGenericMap

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

ToGenericMap converts a map[string]string to a map[string]interface{}

func ToString

func ToString(i interface{}) string

ToString takes an object and tries to convert it to a string

func ToStringMap

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

ToStringMap converts a map[string]interface{} to a map[string]string by using each objects String() fn

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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