configor

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ENV

func ENV() string

ENV return environment

func Load

func Load(config any, files ...string) error

Load will unmarshal configurations to struct from files that you provide

Types

type Config

type Config struct {
	Environment        string
	ENVPrefix          string
	Debug              bool
	Verbose            bool
	Silent             bool
	AutoReload         bool
	AutoReloadInterval time.Duration
	AutoReloadCallback func(config any)

	// In case of json files, this field will be used only when compiled with
	// go 1.10 or later.
	// This field will be ignored when compiled with go versions lower than 1.10.
	ErrorOnUnmatchedKeys bool

	// You can use embed.FS or any other fs.FS to load configs from. Default - use "os" package
	FS fs.FS
}

type Configor

type Configor struct {
	*Config
	// contains filtered or unexported fields
}

func New

func New(config *Config) *Configor

New initialize a Configor

func (*Configor) GetEnvironment

func (c *Configor) GetEnvironment() string

GetEnvironment get environment

func (*Configor) GetErrorOnUnmatchedKeys

func (c *Configor) GetErrorOnUnmatchedKeys() bool

GetErrorOnUnmatchedKeys returns a boolean indicating if an error should be thrown if there are keys in the config file that do not correspond to the config struct

func (*Configor) Load

func (c *Configor) Load(config any, files ...string) (err error)

Load will unmarshal configurations to struct from files that you provide

type UnmatchedTomlKeysError

type UnmatchedTomlKeysError struct {
	Keys []toml.Key
}

UnmatchedTomlKeysError errors are returned by the Load function when ErrorOnUnmatchedKeys is set to true and there are unmatched keys in the input toml config file. The string returned by Error() contains the names of the missing keys.

func (*UnmatchedTomlKeysError) Error

func (e *UnmatchedTomlKeysError) Error() string

Jump to

Keyboard shortcuts

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