confoo

package module
v0.0.0-...-895dbe3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

confoo.go

Yaml based configuration management library for go

Example

Setup the configuration file:

$ export CONFOO_CONFIG_FILE $HOME/confoo.config
$ cat $CONFOO_CONFIG_FILE
test: 
    foo: 
        host: www.paolo.com
        port: 80
        params: 
            p1: mega
            flag: true
		items:
			- field_one: value
			  field_two: value
		options:
			username: john_connor
			password: qwerty

Sample executable:

package main

import (
	"fmt"

	"github.com/enuan/gonfoo"
)

type Options struct {
	Username string
	Password string
}

var config struct {
	Host   string
	Port   int
	Params struct {
		P1   string
		P2   string
		Flag bool
	}
	// slices of any structs
	Items []struct {
		FieldOne string
		FieldTwo string
	}
	// Options pointer fields
	Options *Options
}

func init() {
	config.Host = "foo.bar.com"
	config.Port = 123
	config.Params.P1 = "bar"
	config.Params.P2 = "foo"

	confoo.Configure("test.foo", &config)
}

func main() {
	fmt.Println("config", config)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(path string, target interface{})

Configure loads the value of the path of the yml of the CONFOO_CONFIG_FILE into target

func ConfigureFromFile

func ConfigureFromFile(ymlFile, path string, target interface{}) error

ConfigureFromFile reads ymlFile and loads the value of the path into target

Types

This section is empty.

Jump to

Keyboard shortcuts

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