confetti

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 5 Imported by: 0

README

Confetti

A minimal configuration manager for Go applications.

Quickstart

package main

import (
	"fmt"

	"github.com/shivanshkc/confetti"
)

type configs struct {
	LogLevel string `default:"info" env:"LOG_LEVEL" arg:"log-level"`
	GRPC struct {
		Addr    string `default:"0.0.0.0:9090" env:"GRPC_ADDR" arg:"grpc-addr"`
		Timeout int    `default:"60" env:"GRPC_TIMEOUT" arg:"grpc-timeout"`
	}
}

func main() {
	conf := &configs{}

	loader := confetti.GetLoader()
	if err := loader.Load(conf); err != nil {
		panic(err)
	}

	fmt.Printf("Conf: %+v\n", conf)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotStructPointer is returned when the provided target is not a struct pointer.
	ErrNotStructPointer = fmt.Errorf("target is not a struct pointer")
)

Functions

This section is empty.

Types

type ILoader

type ILoader interface {
	// Load loads the configs into the provided struct.
	//
	// The target should be a struct pointer. The struct fields may have three tags:
	// "default", "env" and "arg".
	//
	// 1. The "default" tag will be accepted as the default value of the field.
	//
	// 2. The "env" tag should hold the name of environment variable bound to the field.
	//
	// 3. The "arg" tag should hold the name of the command-line flag bound to the field. Example:
	//    $ <script> --arg-name=value
	//
	// The order of priority is "arg" > "env" > "default".
	Load(target interface{}) error
	// contains filtered or unexported methods
}

ILoader represents a configuration loader.

func GetLoader

func GetLoader() ILoader

GetLoader returns a new instance of the ILoader.

Jump to

Keyboard shortcuts

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