{"id":19999362,"url":"https://github.com/bios-marcel/yagcl","last_synced_at":"2026-05-08T23:03:22.749Z","repository":{"id":38409723,"uuid":"506556434","full_name":"Bios-Marcel/yagcl","owner":"Bios-Marcel","description":"Yet another golang configuration library","archived":false,"fork":false,"pushed_at":"2023-04-05T14:02:51.000Z","size":1131,"stargazers_count":2,"open_issues_count":9,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-23T16:06:45.974Z","etag":null,"topics":["config","configuration","environment-variables","json"],"latest_commit_sha":null,"homepage":"https://bios-marcel.github.io/yagcl","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bios-Marcel.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,"governance":null}},"created_at":"2022-06-23T08:24:30.000Z","updated_at":"2023-01-15T22:07:58.000Z","dependencies_parsed_at":"2023-01-19T15:25:01.915Z","dependency_job_id":"3c08c44b-dd41-4c19-b3e0-09eb50496319","html_url":"https://github.com/Bios-Marcel/yagcl","commit_stats":{"total_commits":67,"total_committers":3,"mean_commits":"22.333333333333332","dds":"0.28358208955223885","last_synced_commit":"68f7ccc832b6b56edc3ea2538ee0ee00d9dd5dcb"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bios-Marcel%2Fyagcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bios-Marcel%2Fyagcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bios-Marcel%2Fyagcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bios-Marcel%2Fyagcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bios-Marcel","download_url":"https://codeload.github.com/Bios-Marcel/yagcl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241439486,"owners_count":19963095,"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":["config","configuration","environment-variables","json"],"created_at":"2024-11-13T05:11:31.721Z","updated_at":"2026-05-08T23:03:22.677Z","avatar_url":"https://github.com/Bios-Marcel.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yagcl\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/Bios-Marcel/yagcl.svg)](https://pkg.go.dev/github.com/Bios-Marcel/yagcl)\n[![Build and Tests](https://github.com/Bios-Marcel/yagcl/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/Bios-Marcel/yagcl/actions/workflows/test.yml)\n\nThis library aims to provide a powerful and dynamic way to provide\nconfiguration for your application.\n\n## Why\n\nThe thing that other libraries were lacking is the ability to parse different\nformats, allow merging them (for example override a setting via environment\nvariables). Additionally I wanna be able to specify certain things via a reduced\nset and golang defaults.\n\nThe aim is to support all standard datatypes and allow nested structs with specified\nsub prefixes as well as one main prefix.\n\nAdditionally it is planned for the consumer of the library to be able to\nvalidate a struct, essentially making sure it does't contain nonsensical\ncombinations of tags.\n\nFor example, the following wouldn't really make sense, since defining a key\nfor an ignored field has no effect and will therefore result in an error:\n\n```go\ntype Configuration struct {\n    Field string `key:\"field\" ignore:\"true\"`\n}\n```\n\n## Modules\n\n| Name                  | Repo                                                          | Docs                                                                                                                                                 | Status  | Test Coverage                                                                                                                                                             |\n| --------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Main                  | [You are here already!](https://github.com/Bios-Marcel/yagcl) | [![Go Reference yagcl package](https://pkg.go.dev/badge/github.com/Bios-Marcel/yagcl.svg)](https://pkg.go.dev/github.com/Bios-Marcel/yagcl)          | WIP     | [![codecoverage main package](https://codecov.io/gh/Bios-Marcel/yagcl/branch/master/graph/badge.svg?token=BPGE55G1AX)](https://codecov.io/gh/Bios-Marcel/yagcl)           |\n| Environment Variables | [GitHub](https://github.com/Bios-Marcel/yagcl-env)            | [![Go Reference env package](https://pkg.go.dev/badge/github.com/Bios-Marcel/yagcl-env.svg)](https://pkg.go.dev/github.com/Bios-Marcel/yagcl-env)    | WIP     | [![codecoverage env package](https://codecov.io/gh/Bios-Marcel/yagcl-env/branch/master/graph/badge.svg?token=82SUL3UD8H)](https://codecov.io/gh/Bios-Marcel/yagcl-env)    |\n| .env                  | [GitHub](https://github.com/Bios-Marcel/yagcl-env)            | [![Go Reference env package](https://pkg.go.dev/badge/github.com/Bios-Marcel/yagcl-env.svg)](https://pkg.go.dev/github.com/Bios-Marcel/yagcl-env)    | WIP     | [![codecoverage env package](https://codecov.io/gh/Bios-Marcel/yagcl-env/branch/master/graph/badge.svg?token=82SUL3UD8H)](https://codecov.io/gh/Bios-Marcel/yagcl-env)    |\n| JSON                  | [GitHub](https://github.com/Bios-Marcel/yagcl-json)           | [![Go Reference json package](https://pkg.go.dev/badge/github.com/Bios-Marcel/yagcl-json.svg)](https://pkg.go.dev/github.com/Bios-Marcel/yagcl-json) | WIP     | [![codecoverage json package](https://codecov.io/gh/Bios-Marcel/yagcl-json/branch/master/graph/badge.svg?token=6Z45XN9GKZ)](https://codecov.io/gh/Bios-Marcel/yagcl-json) |\n\nAlso check out the [Roadmap](#roadmap) for more detailed information.\n\n## Contribution\n\nThis library is separated into multiple modules. The main module and additional\nmodules for each supported source. This allows you to only specify certain\nsources in your `go.mod`, keeping your dependency tree small. Additionally it\nmakes navigating the code base easier.\n\nIf you wish to contribute a new source, please create a corresponding\nsubmodule.\n\n## Examples\n\nAn example usage may look something like this:\n\n```go\nimport (\n    yagcl_env \"github.com/Bios-Marcel/yagcl-env\"\n    yagcl_json \"github.com/Bios-Marcel/yagcl-json\"\n)\n\ntype Configuration struct {\n    // The `key` here is used to define the JSON name for example. But the\n    // environment variable names are the same, but uppercased.\n    Host string `key:\"host\" required:\"true\"`\n    Post int    `key:\"port\" required:\"true\"`\n    // If you don't wish to export a field, you have to ignore it.\n    // If it isn't ignored and doesn't have an explicit key, you'll\n    // get an error, as this indicates a bug. The reason we don't\n    // auto-generate a key is that this could result in unstable promises\n    // as the variable name could change and break loading of old files.\n    DontLoad    int               `ignore:\"true\"`\n    // Nested structs are special, as they may not be part of your actual\n    // configuration in case you are using environment variables, but will\n    // be if you are using a JSON file. Either way, these also require the\n    // key tag, as we are otherweise unable to build the names for its fields.\n    KafkaServer KafkaServerConfig `key:\"kafka\"`\n}\n\ntype KafkaServerConfig struct {\n    //Alternatively you can define them explicitly. The same goes for json names.\n    Host              string        `json:\"host\" env:\"HOST\" required:\"true\"`\n    Port              int           `json:\"port\" env:\"PORT\" required:\"true\"`\n    ConnectionTimeout time.Duration `json:\"connection_timeout\" env:\"CONNECTION_TIMEOUT\" required:\"false\"`\n}\n\nfunc LoadConfig() error {\n    //Defaults should simply be defined on struct creation.\n    configuration := Configuration{\n        KafkaServer: KafkaServerConfig{\n            Host:              \"localhost\",\n            Port:              1234,\n            ConnectionTimeout: time.Second * 10,\n        },\n    }\n    err := yagcl.\n        New[Configuration]()\n        //This allows ordering when using override, so you can have something like this.\n        Add(yagcl_json.Source().Path(\"/etc/myapp/config.json\").Must()).\n        Add(yagcl_env.Source().Env().Prefix(\"MY_APP_\")).\n        Add(yagcl_json.Source().Path(\"~/.config/config.json\")).\n        AllowOverride().\n        Parse(\u0026configuration)\n    return err\n}\n```\n\nThe configuration loaded by this would look like this:\n\n```json\n{\n    \"host\": \"localhost\",\n    \"port\": 1234,\n    \"kafka\": {\n        \"host\": \"123.123.123.123\",\n        \"port\": 9092,\n        \"connection_timeout\": \"10s\"\n    }\n}\n```\n\nOr this when loading environment variables:\n\n```env\nMY_APP_HOST=localhost\nMY_APP_PORT=1234\nMY_APP_KAFKA_HOST=123.123.123.123\nMY_APP_KAFKA_PORT=9092\nMY_APP_KAFKA_CONNECTION_TIMEOUT=10s\n```\n\n## Usage\n\n**This library isn't stable / feature complete yet, even if it mostly works. The API might change any second ;)**\n\nIf you want to try it out anyway, simply `go get` the desired modules.\n\nFor example:\n\n```shell\ngo get github.com/Bios-Marcel/yagcl-env\n```\n\n## Roadmap\n\n- [x] Basic API\n- [ ] General Features\n  - [ ] Honor `required` tags\n  - [ ] Validation of configuration struct\n  - [ ] Functioning Override mechanism where a whole source is optional or only some fields\n  \u003e While overriding in general works, we'll error as soon as we are missing\n  \u003e one required value in any of the sources.\n- [ ] Read JSON\n  - [x] Honor `key` tags\n  - [x] Honor `json`tags\n  - [x] Honor `ignore` tags\n  - [ ] Type support\n    - [x] int / uint\n    - [x] float\n    - [x] bool\n    - [x] string\n    - [x] struct\n    - [x] pointer\n    - [x] time.Duration\n    - [ ] array (Tests missing)\n    - [ ] map (Tests missing)\n- [ ] Read Environment variables\n  - [x] Honor `key` tags\n  - [x] Honor `env` tags\n  - [x] Honor `ignore` tags\n  - [ ] Type support\n    - [x] int / uint\n    - [x] float\n    - [x] bool\n    - [x] string\n    - [x] struct\n    - [x] pointer\n    - [x] time.Duration\n    - [ ] array\n      - [x] basic types\n      - [ ] Nested array / slice\n      - [ ] map\n      - [ ] struct\n    - [ ] map\n- [x] Read .env files\n  \u003e Will share code with environment variables and should have the same progression.\n\n## Non Goals\n\n* High performance\n  \u003e The code makes use of reflection and generally isn't written with\n  \u003e efficiency in mind. However, this lib is supposed to do a one-time parse\n  \u003e of configuration sources and therefore it shouldn't matter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbios-marcel%2Fyagcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbios-marcel%2Fyagcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbios-marcel%2Fyagcl/lists"}