config

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 6 Imported by: 1

README

config-loader

Config-loader allows you to load configuration values from a file, environment variable and flag whilst using cobra

Usage

In your init() function you will need to call config.Init(cmd) and to register any flags used in the config structure.

You can then define your configuration struct like so with support for both env and flag tags.

type exampleConfig struct {
	Env  string `env:"CONFIG_ENV"`
	Flag string `flag:"CONFIG_FLAG"`
}

Within your executor for the cobra command you then simply run config.Load(cmd, cfg) with cfg being a pointer to the configuration struct.

Example

You can see an example usage of this library in example/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cmd *cobra.Command)

func Load

func Load(cmd *cobra.Command, config interface{}) error

func MustLoad

func MustLoad(cmd *cobra.Command, config interface{})

Types

This section is empty.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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