Skip to content

Latest commit

 

History

History

README.md

Config

Go Reference Go Report Card Coverage Go Version License

A powerful and versatile configuration management package for Go that simplifies handling application settings across different environments and formats.

📚 Complete Documentation →

Documentation

This README provides a quick overview. For comprehensive guides, tutorials, and API reference:

Features

  • Easy Integration: Simple and intuitive API
  • Flexible Sources: Files, environment variables, Consul, custom sources
  • Format Agnostic: JSON, YAML, TOML, and extensible codecs
  • Type Casting: Automatic type conversion (bool, int, float, time, duration)
  • Hierarchical Merging: Multiple sources merged with precedence
  • Struct Binding: Automatic mapping to Go structs
  • Built-in Validation: Struct methods, JSON Schemas, custom functions
  • Dot Notation: Easy nested configuration access
  • Configuration Dumping: Save effective configuration
  • Thread-Safe: Safe for concurrent access
  • Nil-Safe: Graceful handling of nil instances

Installation

go get rivaas.dev/config

Quick Start

package main

import (
    "context"
    "log"
    "rivaas.dev/config"
)

func main() {
    cfg := config.MustNew(
        config.WithFile("config.yaml"),
        config.WithEnv("APP_"),
    )

    if err := cfg.Load(context.Background()); err != nil {
        log.Fatalf("failed to load config: %v", err)
    }

    port := cfg.Int("server.port")
    host := cfg.StringOr("server.host", "localhost")
    
    log.Printf("Server: %s:%d", host, port)
}

See more examples →

Learn More

Contributing

Contributions are welcome! Please see the main repository for contribution guidelines.

License

Apache License 2.0 - see LICENSE for details.