config

package
v0.0.0-...-c5fed4d Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 8 Imported by: 0

README

Config

A convenience wrapper around viper that provides easy-to-use struct-based config loading.

Example

Load Directly
package main

func main() {
	var cfg Config
	opts := []config.Option{
		config.WithEnv(),
	}
	if err := config.Load(&cfg, opts...); err != nil {
		panic(err)
	}

	fmt.Println(cfg)
}

type Config struct {
	Addr   string `default:":8080"`
	StatsD struct {
		Host string `default:"localhost"`
		Port int    `default:"8125"`
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(structPtr interface{}, opts ...Option) error

Load loads configurations into the given structPtr.

Types

type Option

type Option func(l *viperLoader) error

func WithCommand

func WithCommand(cmd *cobra.Command) Option

func WithEnv

func WithEnv(prefix ...string) Option

func WithFile

func WithFile(filePath string) Option

func WithName

func WithName(name string) Option

Jump to

Keyboard shortcuts

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