All Projects → JeremyLoy → Config

JeremyLoy / Config

Licence: mit
12 factor configuration as a typesafe struct in as little as two function calls

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Config

Kubevious
Kubevious - application centric Kubernetes UI and continuous assurance provider
Stars: ✭ 869 (+246.22%)
Mutual labels:  cloud, configuration
Conf
Go package for loading program configuration from multiple sources.
Stars: ✭ 70 (-72.11%)
Mutual labels:  environment, configuration
Cas Configserver Overlay
Generic CAS Spring Cloud Configuration Server WAR overlay
Stars: ✭ 28 (-88.84%)
Mutual labels:  cloud, configuration
envconfig-rs
Build a config structure from environment variables in Rust without boilerplate
Stars: ✭ 135 (-46.22%)
Mutual labels:  environment, configuration
Phpdotenv
Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
Stars: ✭ 11,648 (+4540.64%)
Mutual labels:  environment, configuration
Neovim Init.vim
🏮 The perfect Neovim configuration for productive people who wants to level up their Vim experience with a clean, minimal-looking aesthetic, as well as a highly extensible, easily customizable set of popular tools and shortcuts to boost productivity. 🏮
Stars: ✭ 440 (+75.3%)
Mutual labels:  configuration, minimal
Common Env
🔑 The only configuration library you will ever need
Stars: ✭ 67 (-73.31%)
Mutual labels:  environment, configuration
ngx-env
Easily inject environment variables into your Angular applications
Stars: ✭ 73 (-70.92%)
Mutual labels:  environment, configuration
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-43.43%)
Mutual labels:  environment, configuration
Next Runtime Dotenv
Expose environment variables to the runtime config of Next.js
Stars: ✭ 136 (-45.82%)
Mutual labels:  environment, configuration
environment
🌳 Environment variable configuration for Node.js made easy.
Stars: ✭ 12 (-95.22%)
Mutual labels:  environment, configuration
Drago
A flexible configuration manager for Wireguard networks
Stars: ✭ 204 (-18.73%)
Mutual labels:  cloud, configuration
dotfiles
My personal app/env configs and dotfiles.
Stars: ✭ 27 (-89.24%)
Mutual labels:  environment, configuration
Anura Server
the Anura configuration manger
Stars: ✭ 16 (-93.63%)
Mutual labels:  environment, configuration
laravel-conditional-providers
THIS PACKAGE HAS BEEN DEPRECATED — Load Laravel service providers and facades based on the current environment.
Stars: ✭ 26 (-89.64%)
Mutual labels:  environment, configuration
Erl Env
Make retrieving configuration parameters super fast(7x faster than application:get_env)and stable.
Stars: ✭ 32 (-87.25%)
Mutual labels:  environment, configuration
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-92.83%)
Mutual labels:  environment, configuration
salak.rs
A multi layered configuration loader and zero-boilerplate configuration parser.
Stars: ✭ 27 (-89.24%)
Mutual labels:  environment, configuration
Genie
Distributed Big Data Orchestration Service
Stars: ✭ 1,544 (+515.14%)
Mutual labels:  cloud, configuration
Env
Simple lib to parse environment variables to structs
Stars: ✭ 2,164 (+762.15%)
Mutual labels:  environment, configuration

Config

PkgGoDev Mentioned in Awesome Go Build Status Go Report Card Coverage Status GitHub issues license Release

Manage your application config as a typesafe struct in as little as two function calls.

type MyConfig struct {
	DatabaseUrl string `config:"DATABASE_URL"`
	FeatureFlag bool   `config:"FEATURE_FLAG"`
	Port        int // tags are optional. PORT is assumed
	...
}

var c MyConfig
err := config.FromEnv().To(&c)

How It Works

It's just simple, pure stdlib.

  • A field's type determines what strconv function is called.

  • All string conversion rules are as defined in the strconv package

  • time.Duration follows the same parsing rules as time.ParseDuration

  • If chaining multiple data sources, data sets are merged. Later values override previous values.

    config.From("dev.config").FromEnv().To(&c)
    
  • Unset values remain intact or as their native zero value

  • Nested structs/subconfigs are delimited with double underscore

    • e.g. PARENT__CHILD
  • Env vars map to struct fields case insensitively

    • NOTE: Also true when using struct tags.
  • Any errors encountered are aggregated into a single error value

    • the entirety of the struct is always attempted
    • failed conversions (i.e. converting "x" to an int) and file i/o are the only sources of errors
      • missing values are not errors

Why you should use this

  • It's the cloud-native way to manage config. See 12 Factor Apps
  • Simple:
    • only 2 lines to configure.
  • Composeable:
    • Merge local files and environment variables for effortless local development.
  • small:
    • only stdlib
    • < 180 LoC

Design Philosophy

Opinionated and narrow in scope. This library is only meant to do config binding. Feel free to use it on its own, or alongside other libraries.

  • Only structs at the entry point. This keeps the API surface small.

  • Slices are space delimited. This matches how environment variables and commandline args are handled by the go cmd.

  • No slices of structs. The extra complexity isn't warranted for such a niche usecase.

  • No maps. The only feature of maps not handled by structs for this usecase is dynamic keys.

  • No pointer members. If you really need one, just take the address of parts of your struct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].