Cfginterpolator is an interpolate library in golang allowing to include data from external sources in your configuration

cfginterpolator

example workflow Go Report Card License: MIT

cfginterpolator is an interpolate library in golang allowing to include data from external sources in your configuration

cfginterpolator ingest a map[string]interface{} with as many nested map[string]interface{} as you want.

This data structure can, as example, be produced by:

  • a yaml file read by gopkg.in/yaml.v3

  • a json file read by encoding/json

After cfginterpolator Interpolate job, you can use https://github.com/mitchellh/mapstructure to inject the map[string]interface{} interpolated by cfginterpolator to any kind of struct you defined.

Example

package main

import (
    "github.com/mitchellh/mapstructure"
    "github.com/bbayszczak/cfginterpolator"
)

type Config struct {
    Username string
    Password string
}

var rawConfig = `
---
username: "John-David"
password: "{{env::PASSWORD}}"
`

func main() {
    var config map[string]interface{}
    var configStruct Config
    if err := yaml.Unmarshal([]byte(rawConfig), &config); err != nil {
		panic("cannot unmarshall data: %v", err)
	}
    cfginterpolator.Interpolate(config)
    mapstructure.Decode(config, &configStruct)
}

Available external datasources

environment variables

{{env::ENV_VAR1}} will be replaced by the value of the environment variable ENV_VAR1

External datasources to be implemented

  • environment variables

  • file

  • Hashicorp Vault

  • Hashicorp Consul

Improvements

  • allow to interpolate several times in the same value

  • not panic when interpolator name does not exists

  • add error returns

Owner
Benoit Bayszczak
Devops Engineer @agicap-tech
Benoit Bayszczak
Similar Resources

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

🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP

🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP

config A small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. Example func main() {

Dec 11, 2022

Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Jan 8, 2023

A flexible and composable configuration library for Go that doesn't suck

croconf A flexible and composable configuration library for Go that doesn't suck Ned's spec for Go configuration which doesn't suck: Fully testable: t

Nov 17, 2022

A flexible and composable configuration library for Go that doesn't suck

croconf A flexible and composable configuration library for Go Why? We know that there are plenty of other Go configuration and CLI libraries out ther

Nov 17, 2022

Tinyini - Bare-bones Go library for reading INI-like configuration files

tinyini tinyini is a minimalistic library for parsing INI-like configuration files. example configuration file globalkey = globalvalue [section] key

Jan 10, 2022

✨Clean and minimalistic environment configuration reader for Golang

Clean Env Minimalistic configuration reader Overview This is a simple configuration reading tool. It just does the following: reads and parses configu

Jan 8, 2023

A golang package for parsing ini-style configuration files

Mini Mini is a simple ini configuration file parser. The ini syntax supported includes: The standard name=value Comments on new lines starting with #

Jan 7, 2023

Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Dec 29, 2022
Golang library for managing configuration data from environment variables

envconfig import "github.com/kelseyhightower/envconfig" Documentation See godoc Usage Set some environment variables: export MYAPP_DEBUG=false export

Dec 26, 2022
Small library to read your configuration from environment variables

envconfig envconfig is a library which allows you to parse your configuration from environment variables and fill an arbitrary struct. See the example

Nov 3, 2022
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
Manage local application configuration files using templates and data from etcd or consul

confd confd is a lightweight configuration management tool focused on: keeping local configuration files up-to-date using data stored in etcd, consul,

Dec 27, 2022
YML2FSTAB - Convert from yml data to /etc/fstab configuration

YML2FSTAB - Convert from yml data to /etc/fstab configuration

Nov 1, 2021
Golang library for reading properties from configuration files in JSON and YAML format or from environment variables.

go-config Golang library for reading properties from configuration files in JSON and YAML format or from environment variables. Usage Create config in

Aug 22, 2022
Configure is a Go package that gives you easy configuration of your project through redundancy

Configure Configure is a Go package that gives you easy configuration of your project through redundancy. It has an API inspired by negroni and the fl

Sep 26, 2022
It syncronizes the configuration described in a YAML file against your GitHub Organization

It syncronizes the configuration described in a YAML file against your GitHub Organization. Combined with a CI system, it can be used to implement GitOps for GitHub.

Jul 19, 2021
A minimalist Go configuration library
A minimalist Go configuration library

fig fig is a tiny library for loading an application's config file and its environment into a Go struct. Individual fields can have default values def

Dec 23, 2022
go-up! A simple configuration library with recursive placeholders resolution and no magic.

go-up! A simple configuration library with placeholders resolution and no magic. go-up provides a simple way to configure an application from multiple

Nov 23, 2022