Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make config file in golang elegantly?

Tags:

redis

config

go

I'm a newbie with Golang. I want to write a program to manage my Redis instances so that I can create a Redis connection with specific config file. But I don't know how to create the config file for Redis instances elegantly.

I found "text/template" before, is that a good idea?

like image 994
Papulatus Avatar asked Jan 27 '15 18:01

Papulatus


1 Answers

It depends on the file format you want to support for those configs.

One library able to read most of those format (from a simple ini file to a JSON one) would be spf13/viper:

Viper is a complete configuration solution for go applications. It has been designed to work within an application to handle all types of configuration. It supports

  • setting defaults
  • reading from yaml, toml and json config files
  • reading from environment variables
  • reading from remote config systems (Etcd or Consul)
  • reading from command line flags
  • setting explicit values
like image 61
VonC Avatar answered Sep 28 '22 03:09

VonC