config_loader

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 8 Imported by: 0

README

Config

Basic configuration loader with env overrides support.

Doesn't support nested objects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(opts *LoaderOpts, config Configuration) error

Load loads the configuration from the given config file.

Rules:

- The config file must be either a JSON or YAML file.

- All fields must be exported.

- Fields without env tag will be uppercase and used as environment variable name.

Types

type Configuration

type Configuration interface {
	// DefaultValue returns the default value for the given field.
	DefaultValue(field string) interface{}

	// SetField is used to set the value of a field from environment variables.
	SetField(field string, value interface{})
}

type LoaderOpts

type LoaderOpts struct {
	// contains filtered or unexported fields
}

LoaderOpts

func NewLoaderOpts

func NewLoaderOpts() *LoaderOpts

NewLoaderOpts returns a new LoaderOpts instance.

func (*LoaderOpts) ConfigPath

func (o *LoaderOpts) ConfigPath(path string) *LoaderOpts

ConfigPath sets the path to the config file.

func (*LoaderOpts) EnvPrefix

func (o *LoaderOpts) EnvPrefix(prefix string) *LoaderOpts

EnvPrefix sets the prefix for environment variables. Will capitalize the prefix.

func (*LoaderOpts) ErrorIfNotFound

func (o *LoaderOpts) ErrorIfNotFound(errorIfNotFound bool) *LoaderOpts

ErrorIfNotFound sets the flag that determines whether an error should be returned if the config file is not found.

Jump to

Keyboard shortcuts

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