A dead simple configuration manager for Go applications

Related tags

Configuration store
Overview

Store

Store is a dead simple configuration manager for Go applications.

GoDoc

I didn't like existing configuration management solutions like globalconf, tachyon or viper. First two just don't feel right and viper, imo, a little overcomplicated—definitely offering too much for small things. Store supports either JSON, TOML or YAML out-of-the-box and lets you register practically any other configuration format. It persists all of your configurations in either $XDG_CONFIG_HOME or $HOME on Linux and in %APPDATA% on Windows.

Look, when I say it's dead simple, I actually mean it:

package main

import (
	"log"
	"time"

	"github.com/tucnak/store"
)

func init() {
	// You must init store with some truly unique path first!
	store.Init("cats-n-dogs/project-hotel")
}

type Cat struct {
	Name   string `toml:"naym"`
	Clever bool   `toml:"ayy"`
}

type Hotel struct {
	Name string
	Cats []Cat `toml:"guests"`

	Opens  *time.Time
	Closes *time.Time
}

func main() {
	var hotel Hotel

	if err := store.Load("hotel.toml", &hotel); err != nil {
		log.Println("failed to load the cat hotel:", err)
		return
	}

	// ...

	if err := store.Save("hotel.toml", &hotel); err != nil {
		log.Println("failed to save the cat hotel:", err)
		return
	}
}

Store supports any other formats via the handy registration system: register the format once and you'd be able to Load and Save files in it afterwards:

store.Register("ini", ini.Marshal, ini.Unmarshal)

err := store.Load("configuration.ini", &object)
// ...
You might also like...
goconfig uses a struct as input and populates the fields of this struct with parameters from command line, environment variables and configuration file.

goconfig goconfig uses a struct as input and populates the fields of this struct with parameters from command line, environment variables and configur

Go configuration made easy!

gofigure Go configuration made easy! Just define a struct and call Gofigure Supports strings, ints/uints/floats, slices and nested structs Supports en

Harvest configuration, watch and notify subscriber

Harvester Harvester is a configuration library which helps setting up and monitoring configuration values in order to dynamically reconfigure your app

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

🛠 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() {

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

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

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 #

Go configuration with fangs
Go configuration with fangs

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/

Comments
  • changed the yaml dependency

    changed the yaml dependency

    This change is required in order for the 'dep' tool to manage its dependencies correctly. The yaml package is provided by gopkg.in instead of github.com (this seems like a quirk to me; it would better to use tags and keep the code on github IMHO but the yaml developers didn't do this).

    opened by rickb777 1
  • Readme example code is invalid

    Readme example code is invalid

    The example code in the Readme is invalid

    main.go:6: imported and not used: "os"
    main.go:23: undefined: time in time.Time
    main.go:24: undefined: time in time.Time
    main.go:37: no new variables on left side of :=
    
    opened by nicholascapo 0
  • Example (and my own code) doesn't work

    Example (and my own code) doesn't work

    The example in README.md gives following error:

    panic: unexpected reflect.Kind: uintptr [recovered]
    panic: unexpected reflect.Kind: uintptr
    

    Same example but saving to ´yaml´ gives the following error:

    panic: reflect.Value.Interface: cannot return value obtained from unexported field or method [recovered]
    panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
    

    Saving to json seems to work however. All of this is on Windows 10 go1.10.2 windows/amd64

    opened by coroiu 1
  • applicationName?

    applicationName?

    Why do we need applicationName? If we do not provide it, the lib can use local config path, for example store.Load("./config.yaml", &config)

    opened by puzanov 0
Releases(v1.0)
  • v1.0(Jul 7, 2016)

    I didn't like existing configuration management solutions like globalconf, tachyon or viper. First two just don't feel right and viper, imo, a little overcomplicated—definitely offering too much for small things. That's why I made Store. It supports either JSON, TOML or YAML out-of-the-box and lets you register practically any other configuration format. It persists all of your configurations in either $XDG_CONFIG_HOME or $HOME on Linux and in %APPDATA% on Windows.

    After the nine years of development, this is totally production-ready and stable and mature and everything. API is most certainly not gonna change, ever. This release features:

    • Init() for setting up the configuration path.
    • Load() and Save() to load and.. unexpectedly, save the data.
    • Register() for mapping custom file extensions to custom parsers.
    • LoadWith() and SaveWith() for some exotic cases.

    Simple as it gets. Dead. Dead simple. There we go, that's it. Special thanks to me for preparing this wonderful release.

    Source code(tar.gz)
    Source code(zip)
Owner
Ian P Badtrousers
I'm a poet
Ian P Badtrousers
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

Sherif Abdel-Naby 82 Dec 16, 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

Francesco 39 Nov 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.

James Mills 16 Jul 5, 2021
✨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

Ilya Kaznacheev 857 Jan 8, 2023
12 factor configuration as a typesafe struct in as little as two function calls

Config Manage your application config as a typesafe struct in as little as two function calls. type MyConfig struct { DatabaseUrl string `config:"DAT

Jeremy Loy 322 Dec 13, 2022
JSON or YAML configuration wrapper with convenient access methods.

Config Package config provides convenient access methods to configuration stored as JSON or YAML. This is a fork of the original version. This version

Oleg Lebedev 260 Dec 16, 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

Harrison Shoebridge 57 Sep 26, 2022
Load configuration in cascade from multiple backends into a struct

Confita is a library that loads configuration from multiple backends and stores it in a struct. Supported backends Environment variables JSON files Ya

Heetch 456 Jan 1, 2023
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

Vincent Rischmann 229 Nov 3, 2022
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

null 246 Dec 23, 2022