Skip to content

shahob/config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Go Report Card Maintainability

Yet another JSON configuration file reader

Is a lightweight Golang package 🍺

Installation

go get github.com/shahob/config

Usage

JSON configuration file example

{
  "database": {
    "host": "localhost",
    "port": 5432,
    "password": "password",
    "user": "user",
    "database": "database"
  }
}

Create Config struct type from JSON format

type Database struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Password string `json:"password"`
	User     string `json:"user"`
	Base     string `json:"database"`
}

type Config struct {
	Database `json:"database"`
}
import (
	"fmt"

	"github.com/shahob/config"
)

configuration := Config{}

// get configuration file
err := config.Load(*configPath, &configuration)

if err != nil {
	fmt.Println(err.Error())
}

fmt.Println(configuration.Database.Host)

License

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