iutils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package iutils provides specific helpers for internal use.

Code generated by "string-enumer -t Format -o format_enumer___generated.go ."; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSource = errors.New("invalid source")

ErrInvalidSource is returned when the source is invalid.

Functions

func Any

func Any[T comparable](args ...T) T

Any returns the first non-zero value from the provided arguments.

func LoadDotEnv

func LoadDotEnv(path file.File) (env.Env, error)

LoadDotEnv loads environment variables from a .env file.

func MatchEnvToFlag

func MatchEnvToFlag(name Prefix) func(string) string

MatchEnvToFlag allows the env provider of koanf to property match stuff like: APP_REGISTRY_TOKEN -> registry-token when name is for example "APP_".

func Merge

func Merge[T any](dst, src *T, opts ...func(*mergo.Config)) (err error)

Merge merges the source and destination values. It uses the mergo package to perform the merge. The destination value is modified in place. The source value is deep-copied to avoid modifying the original. The function accepts options for the merge operation. If no options are provided, it uses the default options: mergo.WithOverride and mergo.WithoutDereference.

func Print

func Print(format Format, cfg ...any)

Print displays the configuration in the specified format.

func ReadPaths

func ReadPaths(paths ...string) ([]byte, error)

ReadPaths reads from one or more file paths or "-" (stdin), and returns concatenated data.

func ReadPathsOrDefault

func ReadPathsOrDefault(defaultPath string, args ...string) ([]byte, error)

ReadPathsOrDefault reads from args if provided, or from defaultPath if args is empty.

func SplitTags

func SplitTags(tagList []string) tags.IncludeTags

SplitTags splits tags into include and exclude lists.

func StructToKoanf

func StructToKoanf(s any) (*koanfx.Koanf, error)

StructToKoanf converts a struct to a `koanf` instance, using the "yaml" tag for field names.

Types

type BytesSource

type BytesSource struct {
	Data []byte
}

BytesSource represents pre-loaded bytes.

func (BytesSource) Read

func (s BytesSource) Read() ([]byte, error)

Read implements Source.

type FileSource

type FileSource struct {
	File file.File
}

FileSource reads from a file.

func (FileSource) Read

func (s FileSource) Read() ([]byte, error)

Read implements Source.

type Format

type Format string

Format represents the output format for displaying configuration.

const (
	// JSON represents JSON format.
	JSON Format = "json"
	// YAML represents YAML format.
	YAML Format = "yaml"
	// ENV represents environment variable format.
	ENV Format = "env"
)

func FormatValues

func FormatValues() []Format

FormatValues returns a list of all (valid) Format values

func (Format) Valid

func (v Format) Valid() bool

Valid validates if a value is a valid Format

type MultiSource

type MultiSource struct {
	Sources []Source
}

MultiSource reads from multiple sources and concatenates the results.

func NewMultiSource

func NewMultiSource(sources ...Source) *MultiSource

NewMultiSource creates a new multi source.

func (MultiSource) Read

func (s MultiSource) Read() ([]byte, error)

Read implements Source.

type Prefix

type Prefix string

Prefix represents a prefix string used for configuration keys.

func (Prefix) Lower

func (p Prefix) Lower() Prefix

Lower returns the lowercase representation of the prefix.

func (Prefix) RemovePrefix

func (p Prefix) RemovePrefix(prefix string) Prefix

RemovePrefix removes the specified prefix from the prefix string.

func (Prefix) RemoveSuffix

func (p Prefix) RemoveSuffix(suffix string) Prefix

RemoveSuffix removes the specified suffix from the prefix string.

func (Prefix) Scoped

func (p Prefix) Scoped() Prefix

Scoped returns a new prefix with an underscore appended.

func (Prefix) String

func (p Prefix) String() string

String returns the string representation of the prefix.

func (Prefix) Upper

func (p Prefix) Upper() Prefix

Upper returns the uppercase representation of the prefix.

func (Prefix) WithUnderscores

func (p Prefix) WithUnderscores() Prefix

WithUnderscores replaces dots with underscores in the prefix string.

type Source

type Source interface {
	Read() ([]byte, error)
}

Source represents a source of input data.

func GetSourceFromPath

func GetSourceFromPath(path string) (Source, error)

GetSourceFromPath determines the appropriate source type for a given path.

type StdinSource

type StdinSource struct{}

StdinSource reads from stdin.

func (StdinSource) Read

func (s StdinSource) Read() ([]byte, error)

Read implements Source.

Jump to

Keyboard shortcuts

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