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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址