8000 GitHub - datatogether/config: Hassle-free config struct setting from env variables in go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.
/ config Public archive

Hassle-free config struct setting from env variables in go

License

Notifications You must be signed in to change notification settings

datatogether/config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Config

GitHub Slack License

config is hassle-free config struct setting for golang, setting things like configStruct.StringField to the value of the enviornment variable STRING_FIELD. It wraps the lovely godotenv package, which itself is a go port of the ruby dotenv gem.

License & Copyright

Copyright (C) 2017 Data Together This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.0.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the LICENSE file for details.

Getting Involved

We would love involvement from more people! If you notice any errors or would like to submit changes, please see our Contributing Guidelines.

We use GitHub issues for tracking bugs and feature requests and Pull Requests (PRs) for submitting changes

Usage

Add config to any golang package with import "github.com/datatogether/config"

Basic use has three steps:

1. declare a struct that defines all your config values (eg: type cfg struct{ ... })
2. (optional) create a file or two that sets enviornement vars.
3. call config.Load(&cfg, "envfilepath")

config will read that env file, setting environment variables for the running process and infer any ENVIRIONMENT_VARIABLE value to it's cfg.EnvironmentVariable counterpart/

config uses a CamelCase -> CAMEL_CASE convention to map values. So a struct field cfg.FieldName will map to an environment variable FIELD_NAME. Types are inferred, with errors returned for invalid env var settings.

Using an env file is optional, calling Load(cfg) is perfectly valid.

config uses the reflect package to infer & set values reflect is a good choice here because setting config happens seldom in the course of a running program, and these days if you're parsing JSON, the reflect package is already included in your binary.

Technical documentation can be built with godoc . or, if your $GOPATH and repo structure is set up correctly, with something like godoc -http=:6060 & followed by browsing to http://localhost:6060/pkg/github.com/datatogether.

Development

Coming soon.

About

Hassle-free config struct setting from env variables in go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

0