• Stars
    star
    1
  • Language
    Go
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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)
}

More Repositories

1

json2react

Use JSON to create React Components.
JavaScript
167
star
2

meteor-simple-i18n

Simple I18n support for meteor
JavaScript
20
star
3

command

Command pattern for Go with thread safe serial and parallel dispatcher
Go
14
star
4

uml.js

ABANDONED - JSON to UML (or something like it)
JavaScript
14
star
5

fw

Micro PHP Framework
PHP
11
star
6

parseargs-go

A string argument parser that understands quotes and backslashes
Go
10
star
7

syte-yii

Syte as a Yii Framework module
JavaScript
5
star
8

itunes-cli

Objective-C
5
star
9

parseargs.js

A string argument parser that understands quotes and backslashes
JavaScript
4
star
10

retry-go

Retry a function execution with specific intervals with panic recovery
Go
4
star
11

meteor-namespace

Namespace helper for Meteor
JavaScript
3
star
12

jslib-dot

Dot notation setter and getter
JavaScript
2
star
13

tic-80-carts

JavaScript
2
star
14

safe

Safe file storage
Go
2
star
15

pigo8

Go
2
star
16

yttr

A cli client for yttr.co
Go
2
star
17

meteor-simple-i18n-sample

https://github.com/txgruppi/meteor-simple-i18n
JavaScript
2
star
18

run

A tool for Docker containers that render config files, extend the environment and run commands
Go
2
star
19

bee.js

A bitwise powered event emitter :-)
JavaScript
2
star
20

acl-go

A simple but powerful Access Control List manager
Go
2
star
21

youtube-cli

Objective-C
1
star
22

errorgroup-go

ErrorGroup is an error type that can hold other errors together.
Go
1
star
23

rproxy

A proxy that applies AES encryption over requests in order to prevent scrapers from easily accessing our data
Go
1
star
24

study-server

Go
1
star
25

fns

A set of Go functions to work with lazy sequences without reflection.
Go
1
star
26

node-gs-dl

Grooveshark Downloader
JavaScript
1
star
27

builtwith-cli

A command line interface for BuiltWith API
Shell
1
star