{"id":13410970,"url":"https://github.com/ThomasObenaus/go-conf","last_synced_at":"2025-03-14T16:33:25.570Z","repository":{"id":47732782,"uuid":"333568113","full_name":"ThomasObenaus/go-conf","owner":"ThomasObenaus","description":"Library for easy configuration of a golang service","archived":false,"fork":false,"pushed_at":"2021-10-19T12:43:09.000Z","size":334,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T20:44:31.254Z","etag":null,"topics":["configuration","go","golang","golang-library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThomasObenaus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-27T21:41:47.000Z","updated_at":"2024-04-04T22:53:55.000Z","dependencies_parsed_at":"2022-08-25T17:41:54.387Z","dependency_job_id":null,"html_url":"https://github.com/ThomasObenaus/go-conf","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasObenaus%2Fgo-conf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasObenaus%2Fgo-conf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasObenaus%2Fgo-conf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThomasObenaus%2Fgo-conf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThomasObenaus","download_url":"https://codeload.github.com/ThomasObenaus/go-conf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243610618,"owners_count":20318999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","go","golang","golang-library"],"created_at":"2024-07-30T20:01:10.553Z","updated_at":"2025-03-14T16:33:25.555Z","avatar_url":"https://github.com/ThomasObenaus.png","language":"Go","funding_links":[],"categories":["配置","Configuration","Uncategorized"],"sub_categories":["标准CLI","Standard CLI","Advanced Console UIs"],"readme":"# go-conf - Configuration with less code\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Reference](https://pkg.go.dev/badge/github.com/ThomasObenaus/go-conf.svg)](https://pkg.go.dev/github.com/ThomasObenaus/go-conf) ![build](https://github.com/ThomasObenaus/go-conf/workflows/build/badge.svg?branch=main) [![Go Report Card](https://goreportcard.com/badge/github.com/ThomasObenaus/go-conf)](https://goreportcard.com/report/github.com/ThomasObenaus/go-conf)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=ThomasObenaus_go-conf\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=ThomasObenaus_go-conf) ![CodeQL](https://github.com/ThomasObenaus/go-conf/workflows/CodeQL/badge.svg)\n\n## Installation\n\n```bash\ngo get github.com/ThomasObenaus/go-conf\n```\n\n## What is go-conf?\n\ngo-conf is a **solution for handling configurations** in golang applications.\n\ngo-conf **supports reading configuration parameters from multiple sources**.\nThe order they are applied is:\n\n1. Default values are overwritten by\n2. Parameters defined in the config-file, which are overwritten by\n3. Environment variables, which are overwritten by\n4. Command-Line parameters\n\nThe aim is to **write as less code as possible**:\n\n- No need to write code to integrate multiple libraries that support reading a configuration from file/ commandline or the environment.\n- No need to code to take the values from that library to fill it into the config struct you want to use in your app anyway.\n\nInstead one just has to define the config structure and annotates it with struct tags.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    config \"github.com/ThomasObenaus/go-conf\"\n)\n\n// Define the config struct and annotate it with the cfg tag.\ntype MyFontConfig struct {\n    Color string `cfg:\"{'name':'color','desc':'The value of the color as hexadecimal RGB string.','default':'#FFFFFF'}\"`\n    Name  string `cfg:\"{'name':'name','desc':'Name of the font to be used.'}\"`\n    Size  int    `cfg:\"{'name':'size','desc':'Size of the font.','short':'s'}\"`\n}\n\nfunc main() {\n\n    // Some command line arguments\n    args := []string{\n        // color not set  --\u003e default value will be used \"--color=#ff00ff\",\n        \"--name=Arial\",\n        \"-s=12\", // use -s (short hand version) instead of --size\n    }\n\n    // 1. Create an instance of the config struct that should be filled\n    cfg := MyFontConfig{}\n\n    // 2. Create an instance of the config provider\n    provider, err := config.NewConfigProvider(\u0026cfg, \"MY_APP\", \"MY_APP\")\n    if err != nil {\n        panic(err)\n    }\n\n    // 3. Read the config and populate the struct\n    if err := provider.ReadConfig(args); err != nil {\n        panic(err)\n    }\n\n    // 4. That's it! Now the config can be used.\n    fmt.Printf(\"FontConfig: color=%s, name=%s, size=%d\\n\", cfg.Color, cfg.Name, cfg.Size)\n}\n\n```\n\n### Features\n\n- Automatically populates a struct using values given via command line\n  - See [simple](examples/simple/)\n  - See [primitive](examples/primitive/)\n- Read config parameters from multiple sources like command line, environment variables and config files (yaml)\n  - See [multisource](examples/multisource/)\n  - See [custom](examples/custom/)\n- Support of default values\n  - See [required](examples/required/)\n- Short hand parameters for command line flags\n- Print usage on command line\n- Custom mapping functions to support parsing of config parameters into complex structures and type conversion\n  - See [mapfun](examples/mapfun/)\n- Support of config parameter lists\n- Support of complex structs with multiple levels\n  - See [multilevel](examples/multilevel/)\n  - See [external](examples/external/)\n\n## License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FThomasObenaus%2Fgo-conf.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FThomasObenaus%2Fgo-conf?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThomasObenaus%2Fgo-conf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FThomasObenaus%2Fgo-conf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThomasObenaus%2Fgo-conf/lists"}