confer

package module
v0.0.0-...-67a669d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: CC0-1.0 Imports: 4 Imported by: 0

README

confer

Yet another configuration library for go

There is a common program configuration case in which the program receives the path to the file as the only argument and reads the configuration from this file.
This library provides the only function that parses the toml file along the path passed in the arguments.

Install

$ go get github.com/DomesticMoth/confer

Usage

package main

import  (
	"github.com/DomesticMoth/confer"
	"fmt"
)

type Config struct {
	SomeParam string
}

func main() {
  var conf Config
  err := confer.LoadConfig([]string{}, &conf)
  if err != nil {
    panic(err)
  }
  fmt.Println(conf)
}

It also provides the ability to specify one or more default paths by which the file will be searched if no path was passed through arguments or if the configuration could not be loaded using the passed path.

package main

import  (
	"github.com/DomesticMoth/confer"
	"fmt"
)

type Config struct {
	SomeParam string
}

func main() {
  defaultLocalPath := "~/cofigfile"
  defaultGloabalPath := "/etc/cofigfile"
  var conf Config
  err := confer.LoadConfig([]string{defaultLocalPath, defaultGloabalPath}, &conf)
  if err != nil {
    panic(err)
  }
  fmt.Println(conf)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(paths []string, conf interface{}) (err error)

Load configuration from toml file located on the path passed in the arguments or on one of the default paths.

Types

This section is empty.

Jump to

Keyboard shortcuts

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