konf

package
v0.0.0-...-5783bb9 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package konf provides utilities to work with `github.com/nil-go/konf`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLocations

func DefaultLocations(appName, fileName string) []string

DefaultLocations returns a common set of paths where to look for a configuration file.

  • /etc/appName/fileName (on linux and darwin)
  • /${HOME}/appName/fileName
  • /${HOME}/.appName/fileName
  • `pwd`/fileName

func FlagsLoader

func FlagsLoader(config *Config, flags *flag.FlagSet, splitter string) lib.Loader

FlagsLoader checks the config instance to verify if the defined flags have been set by other providers. If not, default flag values are merged. If they exist, flag values are merged only if explicitly set in the command line.

func PflagsLoader

func PflagsLoader(config *Config, flags *pflag.FlagSet, splitter string) lib.Loader

PflagsLoader checks the config instance to verify if the defined pflags have been set by other providers. If not, default pflag values are merged. If they exist, pflag values are merged only if explicitly set in the command line. The `splitter` value is used to split flag names into nested keys, if not provided the default value "." will be used.

Types

type Config

type Config = lib.Config

Config reads configuration from appropriate sources.

To create a new Config, call Setup.

func Setup

func Setup(opts ...Option) (config *Config, err error)

Setup returns a new configuration handler instance.

type Option

type Option func(*settings) error

Option instances adjust the behavior of a configuration provider.

func WithEnv

func WithEnv(prefix string) Option

WithEnv adjust the configuration provider to load values from ENV variables. If a `prefix` is provided only ENV variables with it will be evaluated. The provided `prefix` value will be automatically formatted, for example: `myapp` will be evaluated as `MYAPP_`.

func WithFileLocations

func WithFileLocations(locations []string) Option

WithFileLocations adjust the configuration provider to attempt to load a configuration file form the local filesystem. The first valid configuration file found will be the one used.

func WithFlags

func WithFlags(set *flag.FlagSet) Option

WithFlags loads configuration values coming from "command-line" flags.

func WithPflags

func WithPflags(set *pflag.FlagSet) Option

WithPflags loads configuration values coming from "command-line" flags using the `github.com/spf13/pflag` package.

func WithTagName

func WithTagName(name string) Option

WithTagName adjust the tag identifier is used when decoding configuration into structs. For example, with the tag name `konf`, it would look for `konf` tags on struct fields. If no value is provided a sane default will be used depending on the configuration file extension.

Jump to

Keyboard shortcuts

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