Skip to content

GoRealConf is a type-safe dynamic configuration management library for Go applications

License

Notifications You must be signed in to change notification settings

samuelarogbonlo/gorealconf

Repository files navigation

gorealconf

Go Reference Build Status

gorealconf is a powerful, type-safe dynamic configuration management library designed for modern Go applications. With support for real-time updates, multiple configuration sources, and gradual rollouts, it ensures zero-downtime deployments while maintaining operational stability.

Table of Contents

Documentation

Installation

Latest version:

go get github.com/samuelarogbonlo/gorealconf

Specific version:

go get github.com/samuelarogbonlo/[email protected]

Quick Start

  1. Define your configuration:
type AppConfig struct {
    ServerPort int           `json:"server_port"`
    Timeout    time.Duration `json:"timeout"`
}
  1. Create and use configuration:
cfg := gorealconf.New[AppConfig]()

// Add validation
cfg = gorealconf.New[AppConfig](
    gorealconf.WithValidation[AppConfig](func(old, new AppConfig) error {
        if new.ServerPort < 1024 {
            return errors.New("port must be >= 1024")
        }
        return nil
    }),
)

// Watch for changes
changes, _ := cfg.Watch(context.Background())
go func() {
    for newCfg := range changes {
        log.Printf("Config updated: %+v", newCfg)
    }
}()

Key Features with Examples

Type-safe Configuration

type Config struct {
    Port    int           `json:"port"`
    Timeout time.Duration `json:"timeout"`
}
cfg := gorealconf.New[Config]()

Multiple Configuration Sources

cfg := gorealconf.New[Config](
    gorealconf.WithSource(fileSource),
    gorealconf.WithSource(etcdSource),
)

Automatic Validation & Rollback

cfg := gorealconf.New[Config](
    gorealconf.WithValidation[Config](validateConfig),
    gorealconf.WithRollback[Config](true),
)

Gradual Rollouts

strategy := gorealconf.NewPercentageStrategy(10)
rollout := gorealconf.NewRollout[Config](cfg).
    WithStrategy(strategy)

Metrics Integration

metrics := gorealconf.NewMetrics("myapp")
cfg.WithMetrics(metrics)

Requirements

  • Go 1.21 or higher
  • Compatible with:
    • etcd v3.5+
    • Consul v1.12+
    • Redis v6+
  • Prometheus for metrics (optional)

Key Features

  • Type-safe Configuration: Ensure your configurations are validated at compile time.
  • Multiple Configuration Sources: Combine Redis, etcd, and files for flexibility.
  • Automatic Validation & Rollback: Catch and rollback bad configurations automatically.
  • Gradual Rollouts: Deploy new configurations incrementally.
  • Metrics Integration: Export configuration change metrics via Prometheus.

Examples

Explore the examples provided to understand how to use gorealconf in different scenarios:

Each example includes inline comments and demonstrates real-world usage scenarios. Visit the examples/ directory for the full code.

Security

For security concerns, please email [email protected]

Support

  • Report bugs via GitHub Issues
  • Join discussions in GitHub Discussions
  • Get community help via GitHub Discussions

Stability Status

Production-Ready: v0.1.0

Contributing

See Contributing Guide for guidelines.

License

MIT License - see LICENSE for details.

About

GoRealConf is a type-safe dynamic configuration management library for Go applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages