Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
World_countries | 1,048 | a month ago | 13 | June 19, 2022 | 7 | other | PHP | |||
Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries | ||||||||||
Featureflags | 572 | 1 | 2 months ago | 33 | January 07, 2020 | mit | Swift | |||
🚩 Allows developers to configure feature flags, run multiple A/B tests or phase feature roll out using a JSON configuration file. | ||||||||||
Config | 447 | 18 | 18 hours ago | 59 | October 16, 2022 | 3 | mit | Go | ||
📝 Go configuration manage(load,get,set,export). support JSON, YAML, TOML, Properties, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名 | ||||||||||
Aconfig | 404 | 16 | 5 months ago | 65 | October 15, 2022 | 10 | mit | Go | ||
Simple, useful and opinionated config loader. | ||||||||||
Goforit | 59 | 25 days ago | 1 | October 25, 2018 | mit | Go | ||||
A feature flags client library for Go | ||||||||||
Paerser | 39 | 16 | 2 months ago | 7 | March 16, 2022 | 2 | apache-2.0 | Go | ||
Country Flag Emoji Json | 39 | 1 | 2 years ago | 4 | September 11, 2021 | cc-by-sa-4.0 | JavaScript | |||
Country flag emojis in JSON format. | ||||||||||
Flagga | 29 | 5 years ago | 1 | July 23, 2018 | mit | Go | ||||
An extensible Go library for handling program configuration using flags. | ||||||||||
Goconf | 23 | 1 | 11 days ago | 5 | January 04, 2022 | unlicense | Go | |||
Configuration loader in Go | ||||||||||
Json Typedef Infer | 22 | a year ago | 4 | mit | Rust | |||||
A CLI tool that generates JSON Typedef schemas from example data |
EnvConf is a Go package, for parsing configuration values from different sources.
go get github.com/antonmashko/envconf
Usually you need a tag with desire configuration sources and execution of a single function envconf.Parse
for getting all configuration values into your golang structure.
Use tags for getting values from different configuration sources.
true
checks that configuration exists in flag
or env
source;bool
, string
, all types of int
and unit
, float32
, float64
, complex64
, complex128
;index out of range
.key1:value1, key2:value2
time.RFC3339
as a time.Parse layout argument;Let's take a look at a simple example. Here we're creating struct with 3 tags for different configuration sources: flag, env, and default value. NOTE: It's not necessary to specify tags for each configuration type, add desired only
package main
import (
"fmt"
"github.com/antonmashko/envconf"
)
type Example struct {
Field1 string `flag:"flag-name" env:"ENV_VAR_NAME" default:"default-value"`
}
func main() {
var cfg Example
if err := envconf.Parse(&cfg); err != nil {
panic(err)
}
fmt.Printf("%#v\n", cfg)
}
Testing!
If you want to get set Field1
from command line flag, use flag name that is set in flag
tag.
$ go run main.go -flag-name="variable-from-flag"
main.Example{Field1:"variable-from-flag"}
The same result would be for other configuration types.
-help
outputUsing envconf will also generate help output with all registered fields and types. Use flag -help
or -h
for getting it.
$ go run main.go -help
Usage:
Field1 <string> default-value
flag: flag-name
environment variable: ENV_VAR_NAME
required: false
description: ""
EnvConf can generate environment variable name or flag name from golang field path. All you need is to set *
in specific tag. For environment variables name envconf will use field path in uppercase and underscore as a delimiter.
Example:
type Config struct {
HTTP struct {
Addr string `env:"*"`
}
}
Now we can use HTTP_ADDR
environment variable for defining Addr field.
The same approach will work for flag. But flag names will be generated in lowercase and the dash will be as a delimiter.
In case if parent struct name doesn't satisfy for configuration variable name, it can be changed with envconf
tag.
Example:
type Config struct {
HTTP struct {
Addr string `env:"*"`
} `envconf:"httpserver"`
}
Now we'll get HTTPSERVER_ADDR
as environment variable name.
See: EnvConf example
Priority:
1) Flag
2) Environment variable
3) External source
4) Default value