configutil

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidConfigFileExtensions = []string{"toml", "yaml", "yml", "json"}
)

Functions

func FromConfigString

func FromConfigString(config, configType string, data interface{}) error

FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.

func FromFile

func FromFile(fs afero.Fs, filename string, data interface{}) error

FromFile loads the configuration from the given filename.

func GetFileExtension

func GetFileExtension(filename string) string

GetFileExtension return the extension of specfied filename

func IsValidConfigFilename

func IsValidConfigFilename(filename string) bool

IsValidConfigFilename returns whether filename is one of the supported config formats.

Example:

  configData := &Configuration{}
	 if !configutil.IsValidConfigFilename(configFile) {
	 	return fmt.Errorf("invalid config file: %s", configFile)
	 }
	 err := configutil.FromFile(afero.NewOsFs(), configFile, configData)
	 if err != nil {
	 	return err
	 }

Types

This section is empty.

Jump to

Keyboard shortcuts

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