goconf

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 5 Imported by: 0

README

Go Config

Library to load env configuration

How to use it
package main
import (

"errors"
"github.com/caarlos0/env/v6"
"github.com/wgarunap/goconf"
"log"
)

type Conf struct {
	Name string `env:"MY_NAME"`
}

var Config Conf

func (Conf) Register()error {
	return env.Parse(&Config)
}

func (Conf) Validate() error{
	if Config.Name == "" {
		return errors.New(`MY_NAME environmental variable cannot be empty`)
	}
    return nil
}

func (Conf) Print() interface{} {
	return Config
}

func main() {
	err := goconf.Load(
		new(Conf),
	)
    if err != nil{
           log.Fatal(err)
    }
    log.Print(`configuration loaded, `,Config.Name)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(configs ...Configer) error

Types

type Configer

type Configer interface {
	Register() error
}

type Printer

type Printer interface {
	Print() interface{}
}

type Validater

type Validater interface {
	Validate() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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