util

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnySlice

func AnySlice[T any](in []T) []any

func ConvertSliceToAny added in v0.17.0

func ConvertSliceToAny[T any](ts []T) []any

ConvertSliceToAny converts a slice of some type to slice of any. Returns nil if the input slice is nil.

func ConvertStringSlicePtr added in v0.9.0

func ConvertStringSlicePtr[T ~string](ss []string) *[]T

ConvertStringSlicePtr converts a slice of strings to a pointer to another string-like type. Returns nil if the input slice is nil.

func Deref

func Deref[T any](val *T) T

func DerefStr

func DerefStr[T ~string](val *T) string

func ExpandPath added in v0.4.0

func ExpandPath(path string) string

ExpandPath expands environment variables and tilde in file paths. It handles: - Empty paths (returns empty string) - Environment variable expansion (e.g., $HOME/config) - Home directory expansion (e.g., ~/config or ~) - Path normalization for cross-platform compatibility

func IsCI added in v0.10.0

func IsCI() bool

IsCI determines if the current execution context is within a known CI/CD system. This is based on https://github.com/watson/ci-info/blob/HEAD/index.js.

func IsTerminal added in v0.10.0

func IsTerminal(w io.Writer) bool

IsTerminal is a helper method for detecting whether an io.Writer is a interactive terminal / TTY.

func Must

func Must[T any](v T, err error) T

func Ptr

func Ptr[T any](val T) *T

func PtrIfNonNil added in v0.19.3

func PtrIfNonNil[T ~[]E, E any](val T) *T

func SerializeToJSON added in v0.10.0

func SerializeToJSON(w io.Writer, v any) error

func SerializeToYAML added in v0.10.0

func SerializeToYAML(w io.Writer, v any) error

SerializeToYAML serializes data to YAML format.

This function first marshals to JSON, then unmarshals and encodes to YAML. This approach ensures that:

  1. Structs from third-party libraries or generated code that only include json: struct tags (without yaml: tags) are correctly marshaled
  2. JSON and YAML marshaling produce consistent output, both respecting the same json: tags and omitempty directives

Types

type Duration added in v0.19.0

type Duration struct {
	time.Duration
}

Duration is a wrapper around time.Duration that allows it to be marshalled to/from JSON via the standard duration string format.

func (Duration) MarshalText added in v0.19.0

func (d Duration) MarshalText() ([]byte, error)

Implements the encoding.TextMarshaler interface.

func (*Duration) UnmarshalText added in v0.19.0

func (d *Duration) UnmarshalText(b []byte) error

Implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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