Quick and easy way to load config files based on a simple set of rules.

GoDoc Codeship Codecov Go Report Card

config

Quick and easy way to load config files based on a simple set of rules.

Project inspired by https://github.com/lorenwest/node-config

Important stuff

Supported files

Before you can load any file you must register parsers using Loader.RegisterParser.

Each parser has a list of supported extensions that will be used to find files to load.

Config folder

By default the load will try to find the files based on the environment variable name given to it (defaults to CONFIG_DIR). If the variable name is empty or the variable value is empty, it will look for files in ./config.

File load order

default.{ext}
{deployment}.{ext}
{hostname}.{ext}
{hostname}-{deployment}.{ext}
local.{ext}
local-{deployment}.{ext}

Where

  • {ext} is one of the registered extensions.
  • {deployment} is the deployment name, from the $ENV environment variable. (No default value, ignored if empty)
  • {hostname} is the value returned from os.Hostname() with no changes. (No default value, ignored if empty)

Installation

go get -u github.com/txgruppi/config

Example

package main

import (
	"fmt"
	"log"

	"github.com/txgruppi/config"
	"github.com/txgruppi/config/parsers/json"
)

type Config struct {
	Server struct {
		Bind string `json:"bind"`
		Port int    `json:"port"`
	} `json:"server"`
}

func main() {
	loader := NewLoader()
	if err := loader.RegisterParser(json.NewParser()); err != nil {
		log.Fatal(err)
	}
	var config Config
	info, err := loader.Load(&config)
	if err != nil {
		log.Fatal(err)
	}
  fmt.Printf("Looked for files in: %s\n", info.ConfigFolder)
	fmt.Printf("Loaded files: %v\n", info.LoadedFiles)
	fmt.Printf("Loaded config: %v\n", config)
}
Owner
Similar Resources

App that generates a Matterbridge config file based on channel names.

Matterbridge Auto-Config App that generates a Matterbridge config file based on channel names. This remote configuration file* is generated based on s

Oct 15, 2022

Simple, useful and opinionated config loader.

aconfig Simple, useful and opinionated config loader. Rationale There are many solutions regarding configuration loading in Go. I was looking for a si

Dec 26, 2022

Simple Config Format for Golang.

IndentText Simple Configuration Format that tries to be easy to use and understand at a glance. Unlike other formats, IndentText does not have any typ

Nov 26, 2021

A simple multi-layered config loader for Go. Made for smaller projects. No external dependencies.

config ⚠️ Work in progress! A simple multi-layered config loader for Go. Made for smaller projects. No external dependencies. Installation go get -u g

Dec 26, 2021

Composable, observable and performant config handling for Go for the distributed processing era

Konfig Composable, observable and performant config handling for Go. Written for larger distributed systems where you may have plenty of configuration

Dec 11, 2022

Sidecar to watch a config folder and reload a process when it changes

A small (3MB uncompressed docker image), efficient (via inotify) sidecar to trigger application reloads when configuration changes.

Dec 29, 2022

Viper wrapper with config inheritance and key generation

piper - Simple Wrapper For Viper Single Source of Truth Generated Key Structs, No Typo Config Inheritance Multiple Config Strategies Support Cache For

Sep 26, 2022

A lightweight yet powerful config package for Go projects

Config GoLobby Config is a lightweight yet powerful config package for Go projects. It takes advantage of env files and OS variables alongside config

Dec 11, 2022

go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config

HOCON (Human-Optimized Config Object Notation) Configuration library for working with the Lightbend's HOCON format. HOCON is a human-friendly JSON sup

Dec 3, 2022
Related tags
⚙️ Dead Simple Config Management, load and persist config without having to think about where and how.

Configo Dead Simple Config Management, load and persist config without having to think about where and how. Install go get github.com/UltiRequiem/conf

Apr 6, 2022
Jul 4, 2022
Go-config - Config parser for go that supports environment vars and multiple yaml files

go-multiconfig This package is able to parse yaml config files. It supports gett

Jun 23, 2022
shops is a simple command-line tool written in Go that helps you simplify the way you manage configuration across a set of machines.

shops is a simple command-line tool written in Go that helps you simplify the way you manage configuration across a set of machines. shops is your configuration management tool of choice when Chef, Puppet, Ansible are all too complicated and all you really want to do is run a bunch of regular shell against a set of hosts.

Jul 5, 2021
Gonfigure - Read and write config files in go

Gonfigure Reads ini files in golang. Reading INI Files Load file File can be loa

Jan 27, 2022
Config files for my GitHub profile.

hcltm Threat Modeling with HCL Overview There are many different ways in which a threat model can be documented. From a simple text file, to more in-d

Dec 7, 2021
Config files for my GitHub profile.
Config files for my GitHub profile.

swag ?? English ∙ 简体中文 Swag converts Go annotations to Swagger Documentation 2.0. We've created a variety of plugins for popular Go web frameworks. Th

Dec 7, 2021
nflex - common interface to parsed config files

nflex - common interface to parsed config files Install: go get github.com/muir/

Dec 29, 2021
Config files for my GitHub profile.
Config files for my GitHub profile.

Distributed server for social and realtime games and apps. Features Users - Register/login new users via social networks, email, or device ID. Storage

Jan 13, 2022
Quick and simple Go application that fixes updates on non TPM, UEFI devices on the latest insider builds.
Quick and simple Go application that fixes updates on non TPM, UEFI devices on the latest insider builds.

W11-Updater Quick and simple Go application that fixes updates on non TPM, UEFI devices on the latest insider builds. Sick of this bullshit? Build Ins

Oct 21, 2021