config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigFile added in v0.2.0

func GetConfigFile(cmdline []string, envName string) (string, error)

GetConfigFile returns the path to a config file if one is specified

This function will automatically add the `-config` flag to the calling program and parse the cmdline to determine if it has been specified. If the `-config` flag is not specified, this will fall back to trying to get a path to a config file from the specified environment variable

func RegisterValidator

func RegisterValidator(name string, f func(reflect.Value, string, *ConfTags) error) error

RegisterValidator registers a custom validator to be used for validating a value

Note:

Once a validator is registered, its name can be used in the validators
struct field tag

func Run

func Run(target any, filename string, hint string) error

Run reads all configuration into the configuration structs and then validates the stored data

Notes:

`target` must be a pointer to a struct
`filename` is optional
	This is the full path to a configuration file
		supported: json, toml, or yaml
	If not provided, reading from a configuration file will not
	be done.
`hint` is optional
	Must be one of: json, toml, or yaml
	Only needed if a configuration file does not follow standard
	extensions.
		json = *.json
		toml = *.toml
		yaml = *.yml or *.yaml
	Only needed if `filename` is provided

Types

type ConfTags added in v0.0.2

type ConfTags struct {
	Acceptable []string
	EnvName    string
	Executors  []string
	IfEmpty    string
	IfZero     string
	Validators []string
}

ConfTags holds the struct tag configuration options

Jump to

Keyboard shortcuts

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