A minimal configuration manager for Go applications.

Confetti

A simple config manager for Go applications.

Install

Use the following:

go get -u github.com/shivanshkc/confetti/v2

When to use Confetti

Confetti only has a few, but well implemented set of features. It makes it really easy to use and understand.
If your application fits the following use-case, Confetti is the best config manager you can get.

  1. The configs have to be loaded/unmarshalled into a struct.
  2. The configs are loaded once at application startup and do not change for the entire runtime of the application.
  3. The configs are loaded either from the environment or command-line flags (No JSON/YAML files or remote servers).

Beauty of Confetti

If your application agrees with the above restrictions, you can enjoy the following features of Confetti:

  1. Concise syntax using struct tags

    package main
    
    type Configs struct {
        Port string `def:"8080" env:"PORT" arg:"port"`
    }

    This is all you need to make a struct usable with Confetti. Use the following code to load the configs:

    import (
        "fmt"
    
        "github.com/shivanshkc/confetti/v2"
    )   
    
    func main() {
        loader := confetti.NewDefLoader()
    
        configs := &Configs{}
        if err := loader.Load(configs); err != nil {
            panic(err)
        }
    
        fmt.Println("Configs:", configs)
    }

    Here, as you may have guessed:
    a. The Port config has the default value of 8080.
    b. If the environment variable PORT is provided, it will override the default value.
    c. If the -port or --port flag is provided, it will override both the default value and the environment variable.

  2. Generates documentation for your application

    If you use the code in the last point, and execute go run main.go -h, you will see the following on your console:

    Usage of configs:
    -port value
            Doc: not provided
            Default: 8080
            Environment: PORT
    panic: failed to parse flags: flag: help requested
    

    Confetti auto-generates this help documentation for your application using Go's flag package.
    In the output above, notice the Doc: not provided line. This is because we did not provide any doc on the Port config. It can be provided as follows:

    type Configs struct {
        Port string `def:"8080" env:"PORT" arg:"port,HTTP server port"`
    }

    Now, the output will read:

    Usage of configs:
    -port value
        Doc: HTTP server port
        Default: 8080
        Environment: PORT
    panic: failed to parse flags: flag: help requested
    

    Next, you must be getting annoyed by the panic message at the bottom. This is because Go's flag package returns an error when a -h or -help flag is provided. To get rid of this, use the following:

    import (
        "errors"
        "fmt"
    
        "github.com/shivanshkc/confetti/v2"   
    )
    
    func main() {
        loader := confetti.NewDefLoader()
    
        configs := &Configs{}
        if err := loader.Load(configs); err != nil {
            if errors.Is(err, flag.ErrHelp) {
    	        return
            }
            panic(err)
        }
    
        fmt.Println("Configs:", configs)
    }
  3. Nested structs

    Confetti is built to handle nested structs. Just make sure that the flag names for all fields are always different, otherwise you'll get a panic.

    type Configs struct {
        HTTP struct {
            Port string `def:"8080" env:"HTTP_PORT" arg:"http-port"`
        }
    
        GRPC struct {
            Port string `def:"7070" env:"GRPC_PORT" arg:"grpc-port"`
        }
    }

    The above struct is a completely valid Confetti target.

  4. Automatic type assertions

    Confetti is built to handle all types of configs, and not just strings. Consider the following example:

    type Configs struct {
        CORS struct {
            TrustedOrigins []string `def:"[\"google.com\"]" env:"TRUSTED_ORIGINS" arg:"trusted-origins"`
        }
    
        Pagination struct {
            DefaultLimit int `def:"100" env:"DEFAULT_LIMIT" arg:"default-limit"`
        }
    
        RedisDetails map[string]string `def:"{}" env:"REDIS_DETAILS" arg:"redis-details"`
    }

    This struct is also a valid Confetti target. Just make sure that the value of the environment variable or flag is a valid JSON string, otherwise Confetti will give you an error.

Confetti options

Confetti exposes a NewLoader function and a NewDefLoader function (as used in the examples above).
The NewDefLoader uses the default options, but users can provide their own options by using the NewLoader function.
Here is the explanation of all available options:

Name Description Default value
Title The title that shows up on help documentation. configs
DefTagName The name of the tag that controls the default value. def
EnvTagName The name of the tag that controls the env variable name. env
ArgTagName The name of the tag that controls the flag name. arg
UseDotEnv Whether to use the .env file if present. false
Owner
Similar Resources

Example of trace instrumentation in Golang applications :bar_chart:

Example of trace instrumentation in Golang applications :bar_chart:

go-opentelemetry-example Example of trace instrumentation in Golang applications using the opentelemetry. Requirements/dependencies Docker Docker-comp

Jun 4, 2022

A dead simple configuration manager for Go applications

Store Store is a dead simple configuration manager for Go applications. I didn't like existing configuration management solutions like globalconf, tac

Dec 24, 2022

Config-loader - Minimal and safe way to load in configuration files without any extra boilerplate, made for my own personal usage

💕 config-loader Minimal and safe way to load in configuration files without any

Jul 4, 2022

gosignal is expected to be used in minimal window manager configurations

gosignal is expected to be used in minimal window manager configurations. It provides a simple battery monitor , which notifies of battery events. It has a config file where you can configure the notification messages given

Mar 21, 2022

Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration, and automating updates to configuration when there is new code to deploy.

Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration, and automating updates to configuration when there is new code to deploy.

Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration (like Git repositories), and automating updates to configuration when there is new code to deploy.

Jan 8, 2023

Utility CLI to convert Spring Boot Yaml configuration into external configuration

boot-config-export Utility CLI to convert Spring Boot Yaml configuration into external configuration (as environment variables). The variables are tra

Nov 17, 2021

Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik Config Validator Note This is currently pre-release software. traefik-config-validator is a CLI tool to (syntactically) validate your Traefik

Dec 16, 2021

A flexible configuration manager for Wireguard networks

A flexible configuration manager for Wireguard networks

Drago A flexible configuration manager for WireGuard networks Drago is a flexible configuration manager for WireGuard networks which is designed to ma

Jan 7, 2023

network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.

network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.

Network Node Manager network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of ku

Dec 18, 2022

Declarative CLI Version manager. Support Lazy Install and Sharable configuration mechanism named Registry. Switch versions seamlessly

aqua Declarative CLI Version manager. Support Lazy Install and Sharable configuration mechanism named Registry. Switch versions seamlessly. Index Slid

Dec 29, 2022

PolarDB Cluster Manager is the cluster management component of PolarDB for PostgreSQL, responsible for topology management, high availability, configuration management, and plugin extensions.

What is PolarDB Cluster Manager PolarDB Cluster Manager is the cluster management component of PolarDB for PostgreSQL, responsible for topology manage

Nov 9, 2022

A Golang package for simplifying storing configuration in the OS-provided secret manager.

go-keyconfig A Golang package for simplifying storing configuration in the OS-provided secret manager. Operating System Support OS Secret Manager MacO

Jul 22, 2022

An opinionated configuration loading framework for Containerized and Cloud-Native applications.

An opinionated configuration loading framework for Containerized and Cloud-Native applications.

Opinionated configuration loading framework for Containerized and 12-Factor compliant applications. Read configurations from Environment Variables, an

Dec 16, 2022

Viper: a complete configuration solution for Go applications including 12-Factor apps

Viper: a complete configuration solution for Go applications including 12-Factor apps

Viper v2 feedback Viper is heading towards v2 and we would love to hear what you would like to see in it. Share your thoughts here: https://forms.gle/

Dec 6, 2021

Go Package Manager (gopm) is a package manager and build tool for Go.

🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 In favor of Go Modules Proxy since Go 1.11, this pr

Dec 14, 2022

painless task queue manager for shell commands with an intuitive cli interface (execute shell commands in distributed cloud-native queue manager).

EXEQ DOCS STILL IN PROGRESS. Execute shell commands in queues via cli or http interface. Features Simple intuitive tiny cli app. Modular queue backend

Dec 14, 2022

Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager) Version 2.x of the AzureRM Provider requires Terraform 0.12.x and later, but 1.0 is recommended. Terra

Oct 16, 2021

Process manager for Procfile-based applications

Hivemind Hivemind is a process manager for Procfile-based applications. At the moment, it supports Linux, FreeBSD, and macOS. Procfile is a simple for

Dec 25, 2022

Process manager for Procfile-based applications and tmux

Process manager for Procfile-based applications and tmux

Overmind Overmind is a process manager for Procfile-based applications and tmux. With Overmind, you can easily run several processes from your Procfil

Jan 4, 2023
Minimal structured logging library for Go
Minimal structured logging library for Go

slog slog is a minimal structured logging library for Go. Install go get cdr.dev/slog Features Minimal API First class context.Context support First c

Dec 29, 2022
A minimal and extensible structured logger

⚠️ PRE-RELEASE ⚠️ DO NOT IMPORT THIS MODULE YOUR PROJECT WILL BREAK package log package log provides a minimal interface for structured logging in ser

Jan 7, 2023
📝 🪵 A minimal level based logging library for Go

slogx A minimal level based logging library for Go. Installation Example Usage Logger Log Level Format Output Contribute License Installation go get g

May 23, 2022
Estats - A minimal metric retrieval system

estats - A minimal metric retrieval system A CLI tool which polls: Load average

Jan 17, 2022
minimal now playing / music log

np === minimalistic 'now playing' music log. POST to add a song/album, GET to retreive log. usage ------ server: $ go build -o np main.go $ ./np -

Feb 22, 2022
exo: a process manager & log viewer for dev
 exo: a process manager & log viewer for dev

exo: a process manager & log viewer for dev exo- prefix – external; from outside. Features Procfile compatible process manager.

Dec 28, 2022
xlog is a logger for net/context aware HTTP applications
xlog is a logger for net/context aware HTTP applications

⚠️ Check zerolog, the successor of xlog. HTTP Handler Logger xlog is a logger for net/context aware HTTP applications. Unlike most loggers, xlog will

Sep 26, 2022
SigNoz helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc. 🔥 🖥. 👉 Open source Application Performance Monitoring (APM) & Observability tool
SigNoz helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc. 🔥 🖥.   👉  Open source Application Performance Monitoring (APM) & Observability tool

Monitor your applications and troubleshoot problems in your deployed applications, an open-source alternative to DataDog, New Relic, etc. Documentatio

Sep 24, 2021
BTFS - The First Scalable Decentralized Storage System - A Foundational Platform for Decentralized Applications

go-btfs What is BTFS? BitTorrent File System (BTFS) is a protocol forked from IPFS that utilizes the TRON network and the BitTorrent Ecosystem for int

Jan 1, 2023