{"id":19152753,"url":"https://github.com/traefik/paerser","last_synced_at":"2025-05-15T10:02:36.141Z","repository":{"id":43133325,"uuid":"287827743","full_name":"traefik/paerser","owner":"traefik","description":"Loads configuration from many sources","archived":false,"fork":false,"pushed_at":"2025-02-13T10:03:17.000Z","size":122,"stargazers_count":60,"open_issues_count":3,"forks_count":19,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-14T16:53:50.068Z","etag":null,"topics":["cli-flags","configuration","environment-variables","go","golang","golang-library","json","toml","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/traefik.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":"2020-08-15T21:30:26.000Z","updated_at":"2025-04-07T16:02:05.000Z","dependencies_parsed_at":"2024-06-18T14:02:46.735Z","dependency_job_id":"7e3edf67-91a5-4b82-9598-d099ad1429b8","html_url":"https://github.com/traefik/paerser","commit_stats":{"total_commits":41,"total_committers":8,"mean_commits":5.125,"dds":"0.19512195121951215","last_synced_commit":"d116c5cea6d8c4541d3dc87db2ddbacb48fa7a95"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fpaerser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fpaerser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fpaerser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fpaerser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traefik","download_url":"https://codeload.github.com/traefik/paerser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319716,"owners_count":22051072,"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":["cli-flags","configuration","environment-variables","go","golang","golang-library","json","toml","yaml"],"created_at":"2024-11-09T08:19:16.379Z","updated_at":"2025-05-15T10:02:34.806Z","avatar_url":"https://github.com/traefik.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Paerser\n\n[![Package documentation](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/traefik/paerser)\n[![Build Status](https://github.com/traefik/paerser/workflows/Main/badge.svg?branch=master)](https://github.com/traefik/paerser/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/traefik/paerser)](https://goreportcard.com/report/github.com/traefik/paerser)\n\n## Features\n\nLoads configuration from many sources:\n\n- CLI flags\n- Configuration files in YAML, TOML, JSON format\n- Environment variables\n\nIt also provides a simple CLI commands handling system.\n\n## Examples\n\n### Configuration\n\n#### CLI Flags\n\n```go\npackage flag_test\n\nimport (\n\t\"log\"\n\n\t\"github.com/davecgh/go-spew/spew\"\n\t\"github.com/traefik/paerser/flag\"\n)\n\ntype ConfigExample struct {\n\tFoo   string\n\tBar   Bar\n\tGreat bool\n}\n\ntype Bar struct {\n\tSub  *Sub\n\tList []string\n}\n\ntype Sub struct {\n\tName  string\n\tValue int\n}\n\nfunc ExampleDecode() {\n\targs := []string{\n\t\t\"--foo=aaa\",\n\t\t\"--great=true\",\n\t\t\"--bar.list=AAA,BBB\",\n\t\t\"--bar.sub.name=bbb\",\n\t\t\"--bar.sub.value=6\",\n\t}\n\n\tconfig := ConfigExample{}\n\n\terr := flag.Decode(args, \u0026config)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tspew.Config = spew.ConfigState{\n\t\tIndent:                  \"\\t\",\n\t\tDisablePointerAddresses: true,\n\t}\n\tspew.Dump(config)\n\n\t// Output:\n\t// (flag_test.ConfigExample) {\n\t// \tFoo: (string) (len=3) \"aaa\",\n\t// \tBar: (flag_test.Bar) {\n\t// \t\tSub: (*flag_test.Sub)({\n\t// \t\t\tName: (string) (len=3) \"bbb\",\n\t// \t\t\tValue: (int) 6\n\t// \t\t}),\n\t// \t\tList: ([]string) (len=2 cap=2) {\n\t// \t\t\t(string) (len=3) \"AAA\",\n\t// \t\t\t(string) (len=3) \"BBB\"\n\t// \t\t}\n\t// \t},\n\t// \tGreat: (bool) true\n\t// }\n}\n```\n\n#### File\n\n```go\npackage file_test\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/davecgh/go-spew/spew\"\n\t\"github.com/traefik/paerser/file\"\n)\n\ntype ConfigExample struct {\n\tFoo   string\n\tBar   Bar\n\tGreat bool\n}\n\ntype Bar struct {\n\tSub  *Sub\n\tList []string\n}\n\ntype Sub struct {\n\tName  string\n\tValue int\n}\n\nfunc ExampleDecode() {\n\ttempFile, err := os.CreateTemp(\"\", \"paeser-*.yml\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tdefer func() { _ = os.RemoveAll(tempFile.Name()) }()\n\n\tdata := `\nfoo: aaa\nbar:\n  sub:\n    name: bbb\n    value: 6\n  list:\n  - AAA\n  - BBB\ngreat: true\n`\n\n\t_, err = fmt.Fprint(tempFile, data)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Read configuration file\n\n\tfilePath := tempFile.Name()\n\n\tconfig := ConfigExample{}\n\n\terr = file.Decode(filePath, \u0026config)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tspew.Config = spew.ConfigState{\n\t\tIndent:                  \"\\t\",\n\t\tDisablePointerAddresses: true,\n\t}\n\tspew.Dump(config)\n\n\t// Output:\n\t// (file_test.ConfigExample) {\n\t// \tFoo: (string) (len=3) \"aaa\",\n\t// \tBar: (file_test.Bar) {\n\t// \t\tSub: (*file_test.Sub)({\n\t// \t\t\tName: (string) (len=3) \"bbb\",\n\t// \t\t\tValue: (int) 6\n\t// \t\t}),\n\t// \t\tList: ([]string) (len=2 cap=2) {\n\t// \t\t\t(string) (len=3) \"AAA\",\n\t// \t\t\t(string) (len=3) \"BBB\"\n\t// \t\t}\n\t// \t},\n\t// \tGreat: (bool) true\n\t// }\n}\n\n```\n\n#### Environment Variables\n\n```go\npackage env_test\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/davecgh/go-spew/spew\"\n\t\"github.com/traefik/paerser/env\"\n)\n\ntype ConfigExample struct {\n\tFoo   string\n\tBar   Bar\n\tGreat bool\n}\n\ntype Bar struct {\n\tSub  *Sub\n\tList []string\n}\n\ntype Sub struct {\n\tName  string\n\tValue int\n}\n\nfunc ExampleDecode() {\n\t_ = os.Setenv(\"MYAPP_FOO\", \"aaa\")\n\t_ = os.Setenv(\"MYAPP_GREAT\", \"true\")\n\t_ = os.Setenv(\"MYAPP_BAR_LIST\", \"AAA,BBB\")\n\t_ = os.Setenv(\"MYAPP_BAR_SUB_NAME\", \"bbb\")\n\t_ = os.Setenv(\"MYAPP_BAR_SUB_VALUE\", \"6\")\n\n\tconfig := ConfigExample{}\n\n\terr := env.Decode(os.Environ(), \"MYAPP_\", \u0026config)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tspew.Config = spew.ConfigState{\n\t\tIndent:                  \"\\t\",\n\t\tDisablePointerAddresses: true,\n\t}\n\tspew.Dump(config)\n\n\t// Output:\n\t// (env_test.ConfigExample) {\n\t// \tFoo: (string) (len=3) \"aaa\",\n\t// \tBar: (env_test.Bar) {\n\t// \t\tSub: (*env_test.Sub)({\n\t// \t\t\tName: (string) (len=3) \"bbb\",\n\t// \t\t\tValue: (int) 6\n\t// \t\t}),\n\t// \t\tList: ([]string) (len=2 cap=2) {\n\t// \t\t\t(string) (len=3) \"AAA\",\n\t// \t\t\t(string) (len=3) \"BBB\"\n\t// \t\t}\n\t// \t},\n\t// \tGreat: (bool) true\n\t// }\n}\n```\n\n### CLI Commands\n\n```go\nTODO\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fpaerser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraefik%2Fpaerser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fpaerser/lists"}