Skip to content

nightails/goconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚙️ goconfig

goconfig is a simple and lightweight configuration management library for Go applications. It provides an easy way to load, save, and create configuration files using structs.

Currently, it supports JSON format, with plans to support YAML and TOML in the future.

✨ Features

  • Load: Read configuration from a file into a struct.
  • Save: Write configuration from a struct into a file.
  • Create: Initialize a new configuration file from a struct (creates directories if they don't exist).
  • Type Safety: Uses Go structs and reflection to ensure type safety.

📦 Installation

go get github.com/nightails/goconfig

🚀 Usage

🛠️ Define your configuration struct

type Config struct {
    Port    int    `json:"port"`
    DBHost  string `json:"db_host"`
    Debug   bool   `json:"debug"`
}

📥 Loading Configuration

cfg := &Config{}
err := goconfig.Load("config.json", cfg)
if err != nil {
    log.Fatalf("Failed to load config: %v", err)
}

📤 Saving Configuration

cfg := &Config{Port: 8080, DBHost: "localhost", Debug: true}
err := goconfig.Save("config.json", cfg)
if err != nil {
    log.Fatalf("Failed to save config: %v", err)
}

🆕 Creating a New Configuration

defaultCfg := &Config{Port: 8080, DBHost: "localhost"}
err := goconfig.Create("config/settings.json", defaultCfg)
if err != nil {
    log.Fatalf("Failed to create config: %v", err)
}

📝 To-Do List (Advanced Features)

  • Multi-format Support: Add support for YAML, TOML, and HCL.
  • Environment Variable Overrides: Allow overriding struct fields using environment variables (e.g., APP_PORT=9000).
  • Validation: Integrate with go-playground/validator to validate configuration values on load.
  • Default Values: Support default value tags in structs.
  • Hot Reloading: Watch configuration files for changes and automatically reload.
  • Remote Config: Support loading configuration from Etcd, Consul, or AWS Secrets Manager.
  • Command Line Flags: Merge configuration with CLI flags.

📄 License

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

About

A simple and lightweight configuration management library for Go applications.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages