gonfig

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 8 Imported by: 1

README

GitHub license Build Status Go Report Card Coverage Status

Gonfig

A simple module to load configurations file to a struct.

Getting Started

To install this package run:

go get github.com/luizvnasc/gonfig
Example

package main

import (
	"fmt"
	"github.com/luizvnasc/gonfig"
)

//Config struct to store the app configuration
type Config struct {
	Version     string `toml:"version"`
	Description string `toml:"desc"`
	Redis       struct {
		Host string `toml:"host"`
		Port uint   `toml:"port"`
	} `toml:"redis"`
}

func main() {
	var config Config
	gonfig.Load("config.toml", &config)
	fmt.Printf("%v", config)
}


You can see more examples here.

Files supported

Extension is supported?
.json
.xml
.yaml/.yml
.toml

Dependencies

Dependency Repository
gopkg.in/yaml.v3 https://github.com/go-yaml/yaml
go-toml github.com/pelletier/go-toml

Authors

  • Luiz Augusto Volpi Nascimento - Initial work - @luizvnasc

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

View Source
const (
	// LoadError = "Error loading the configuration"
	LoadError = GonfigError("Error loading the configuration")
	// UnsupportedFileError = "Unsupported file extension"
	UnsupportedFileError = GonfigError("Unsupported file extension")
)

Variables

This section is empty.

Functions

func Load

func Load(path string, config interface{}) error

Load a struct with the configuration from a config file.

Types

type GonfigError

type GonfigError string

GonfigError is an error in the module.

func (GonfigError) Error

func (g GonfigError) Error() string

Directories

Path Synopsis
examples
xml

Jump to

Keyboard shortcuts

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