Documentation
¶
Index ¶
- Constants
- func AddLogContextValue(ctx context.Context, key string, value interface{}) context.Context
- func BytesString(bytes uint64, accuracy int) string
- func CTFComponentArchiveFilename(name, version string) string
- func CleanMarkdownUsageFunc(cmd *cobra.Command)
- func FormatKey(k string) string
- func FormatList(def string, elems ...KeyInfo) string
- func FormatMap[T DescriptionProvider](def string, elems map[string]T) string
- func GetFileType(fs vfs.FileSystem, path string) (string, error)
- func GetOptionFlag(list ...bool) bool
- func Gzip(data []byte, compressionLevel int) ([]byte, error)
- func IgnoreError(_ error)
- func IndentLines(orig string, gap string, skipfirst ...bool) string
- func JoinIndentLines(orig []string, gap string, skipfirst ...bool) string
- func LoggerWithContextContextValues(ctx context.Context, delegate logr.Logger) logr.Logger
- func MapKeys[K comparable, E any](m map[K]E) []K
- func Must[T any](o T, err error) T
- func Optional[T any](list ...T) T
- func OptionalDefaulted[T any](def T, list ...T) T
- func OptionalDefaultedBool(def bool, list ...bool) bool
- func ParseDeltaTime(s string, past bool) (time.Time, error)
- func ParseURL(urlToParse string) (*url.URL, error)
- func PrintPrettyYaml(obj interface{}, enabled bool)
- func RandomString(n int) string
- func RawJSON(value interface{}) (*json.RawMessage, error)
- func SafeConvert(bytes []byte) string
- func Sort[K Comparable[K]](a []K)
- func SortedMapKeys[K ComparableMapKey[K], E any](m map[K]E) []K
- func SplitLocator(locator string) (string, string, string)
- func StringMapKeys[E any](m map[string]E) []string
- func WriteFileToTARArchive(filename string, contentReader io.Reader, archiveWriter *tar.Writer) error
- type Comparable
- type ComparableMapKey
- type DescriptionProvider
- type KeyInfo
- type LogContextValues
- type StringSet
- type StringSlice
Constants ¶
const ( BYTE = 1.0 << (10 * iota) KIBIBYTE MEBIBYTE GIBIBYTE )
Variables ¶
This section is empty.
Functions ¶
func AddLogContextValue ¶
AddLogContextValue adds a key value pair to the logging context. If none is defined it will be added.
func BytesString ¶
BytesString converts bytes into a human-readable string. This function is inspired by https://www.reddit.com/r/golang/comments/8micn7/review_bytes_to_human_readable_format/
func CTFComponentArchiveFilename ¶
CTFComponentArchiveFilename returns the name of the component archive file in the ctf.
func CleanMarkdownUsageFunc ¶
CleanMarkdownUsageFunc removes Markdown tags from the long usage of the command. With this func it is possible to generate the Markdown docs but still have readable commandline help func. Note: currently only "<pre>" tags are removed.
func FormatList ¶
func GetFileType ¶
func GetFileType(fs vfs.FileSystem, path string) (string, error)
GetFileType returns the mimetype of a file.
func GetOptionFlag ¶
GetOptionFlag returns the flag value used to set a bool option based on optionally specified explicit value(s). The default value is to enable the option (true).
func IgnoreError ¶
func IgnoreError(_ error)
func LoggerWithContextContextValues ¶
LoggerWithContextContextValues creates a new context logger that delegates the actual requests to the delegate but injects the context log values.
func MapKeys ¶ added in v0.3.0
func MapKeys[K comparable, E any](m map[K]E) []K
func Optional ¶
func Optional[T any](list ...T) T
Optional returns the first optional non-zero element given as variadic argument, if given, or the zero element as default.
func OptionalDefaulted ¶
func OptionalDefaulted[T any](def T, list ...T) T
OptionalDefaulted returns the first optional non-nil element given as variadic argument, or the given default element. For value types a given zero argument is excepted, also.
func OptionalDefaultedBool ¶
OptionalDefaultedBool checks all args for true. If no true is given the given default is returned.
func ParseDeltaTime ¶ added in v0.3.0
ParseDeltaTime parses a time diff relative to the actual time and returns the resulting time.
func PrintPrettyYaml ¶
func PrintPrettyYaml(obj interface{}, enabled bool)
PrintPrettyYaml prints the given objects as yaml if enabled.
func RandomString ¶
RandomString creates a new random string with the given length.
func RawJSON ¶
func RawJSON(value interface{}) (*json.RawMessage, error)
RawJSON converts an arbitrary value to json.RawMessage.
func SafeConvert ¶
SafeConvert converts a byte slice to string. If the byte slice is nil, an empty string is returned.
func Sort ¶ added in v0.3.0
func Sort[K Comparable[K]](a []K)
func SortedMapKeys ¶ added in v0.3.0
func SortedMapKeys[K ComparableMapKey[K], E any](m map[K]E) []K
func StringMapKeys ¶
Types ¶
type Comparable ¶ added in v0.3.0
type ComparableMapKey ¶ added in v0.3.0
type ComparableMapKey[K any] interface { Comparable[K] comparable }
type DescriptionProvider ¶
type DescriptionProvider interface {
GetDescription() string
}
type KeyInfo ¶
type KeyInfo interface { DescriptionProvider GetKey() string }
type LogContextValues ¶
type LogContextValues map[string]interface{}
LogContextValues describes the context values.
func ContextWithLogContextValues ¶
func ContextWithLogContextValues(parent context.Context) (context.Context, *LogContextValues)
func LogContextValuesFromContext ¶
func LogContextValuesFromContext(ctx context.Context) *LogContextValues
LogContextValuesFromContext returns the context values of a ctx. If nothing is defined nil is returned.
type StringSlice ¶
type StringSlice []string
func (*StringSlice) Add ¶
func (l *StringSlice) Add(list ...string)
func (StringSlice) Contains ¶
func (l StringSlice) Contains(s string) bool
func (*StringSlice) Delete ¶
func (l *StringSlice) Delete(i int)
func (StringSlice) Sort ¶
func (l StringSlice) Sort()