{"id":16351430,"url":"https://github.com/jieggii/lookupcfg","last_synced_at":"2025-04-12T18:31:02.840Z","repository":{"id":64646253,"uuid":"575764946","full_name":"jieggii/lookupcfg","owner":"jieggii","description":":pencil2: Easily define and populate your configs from any kind of source using lookup function!","archived":true,"fork":false,"pushed_at":"2023-07-28T17:58:47.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-19T05:41:33.736Z","etag":null,"topics":["config-parser"],"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/jieggii.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-08T08:46:05.000Z","updated_at":"2024-11-07T17:59:46.000Z","dependencies_parsed_at":"2024-11-07T15:01:35.143Z","dependency_job_id":"eb633d5e-347f-4685-9410-37cbaade33d5","html_url":"https://github.com/jieggii/lookupcfg","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jieggii%2Flookupcfg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jieggii%2Flookupcfg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jieggii%2Flookupcfg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jieggii%2Flookupcfg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jieggii","download_url":"https://codeload.github.com/jieggii/lookupcfg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248613239,"owners_count":21133474,"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-parser"],"created_at":"2024-10-11T01:09:23.823Z","updated_at":"2025-04-12T18:31:02.562Z","avatar_url":"https://github.com/jieggii.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lookupcfg\nEasily define and populate your configs from any kind of source using lookup function!\n\n## What is lookup function?\n***Lookup function*** is a function which accepts only one argument: **key** (of type `string`) and returns two values:\n* **value** (of type string `string`) - value which matches with the provided **key**\n* **found** (of type `bool`) - is equal to `true` if provided **key** exists and **value** was found. Otherwise, it is equal to `false`\n\nSignature of lookup functions (in Go):\n```go\nfunc(key string) (value string, found bool)\n```\n\n## Installation\n```shell\ngo get github.com/jieggii/lookupcfg\n```\n\n## Usage\nIt's so simple!\n\nFirst of all, define your config struct and create config instance:\n```go\npackage main\n\nimport \"github.com/jieggii/lookupcfg\"\n\nfunc main() {\n    type Config struct {\n        Host string `env:\"HOST\"` // use tags to define source name (key)\n                                 // and value name in this source (value)\n\tPort int `env:\"PORT\"`\n    }\n    config := Config{}\n}\n```\n\nThen choose lookup function which will be used to fill fields of the config struct.\nIn this example we will define own lookup function, which simply uses `os.LookupEnv` function.\n```go\npackage main\n\nimport (\n\t\"github.com/jieggii/lookupcfg\"\n\t\"os\"\n)\n\nfunc lookup(key string) (value string, found bool) {\n\treturn os.LookupEnv(key)\n}\n\nfunc main() {\n\ttype Config struct {\n\t\tHost string `env:\"HOST\"` // use tags to define source name (key)\n                                         // and value name in this source (value)\n\t\tPort int `env:\"PORT\"`\n\t}\n\tconfig := Config{}\n}\n```\n\nLet's finally fill our config with some values from environment variables and print the result!\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/jieggii/lookupcfg\"\n\t\"os\"\n)\n\nfunc lookup(key string) (value string, found bool) {\n\treturn os.LookupEnv(key)\n}\n\nfunc main() {\n\ttype Config struct {\n\t\tHost string `env:\"HOST\"` // use tags to define source name (key)\n                                         // and value name in this source (value)\n\t\tPort int `env:\"PORT\"`\n\t}\n\tconfig := Config{}\n\tresult := lookupcfg.PopulateConfig(\n\t\t\"env\",   // name of the source defined in struct's field tags\n\t\tlookup,  // our lookup function\n\t\t\u0026config, // pointer to our config instance\n\t) // populating our config instance with values from environmental variables\n\n\tfmt.Printf(\"Population result: %+v\\n\", result)\n\t// \u003e\u003e\u003e Population result: \u0026{MissingFields:[] IncorrectTypeFields:[]}\n\n\t// print our populated config instance\n\tfmt.Printf(\"My config: %+v\\n\", config)\n\t// \u003e\u003e\u003e My config: {Host:localhost Port:8888}\n}\n```\nDone!\n\nMore examples can be found in the [examples](https://github.com/jieggii/lookupcfg/tree/master/examples) directory  (´｡• ◡ •｡`) ♡.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjieggii%2Flookupcfg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjieggii%2Flookupcfg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjieggii%2Flookupcfg/lists"}