Is a lightweight Golang package 🍺
go get github.com/shahob/config
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)
This project is licensed under the MIT License - see the LICENSE.md file for details