shahob / config

Yet another JSON configuration file reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Yet another JSON configuration file reader

License:MIT License


Languages

Language:Go 100.0%