{"id":13411170,"url":"https://github.com/goraz/onion","last_synced_at":"2026-01-24T09:35:48.845Z","repository":{"id":35251100,"uuid":"39510839","full_name":"goraz/onion","owner":"goraz","description":"Layer based configuration for golang","archived":false,"fork":false,"pushed_at":"2023-03-07T02:14:06.000Z","size":247,"stargazers_count":118,"open_issues_count":10,"forks_count":16,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2026-01-19T08:59:54.828Z","etag":null,"topics":["config","configuration","golang"],"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/goraz.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":"2015-07-22T14:28:21.000Z","updated_at":"2025-06-24T11:50:57.000Z","dependencies_parsed_at":"2024-04-29T12:03:20.345Z","dependency_job_id":null,"html_url":"https://github.com/goraz/onion","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/goraz/onion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goraz%2Fonion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goraz%2Fonion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goraz%2Fonion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goraz%2Fonion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goraz","download_url":"https://codeload.github.com/goraz/onion/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goraz%2Fonion/sbom","scorecard":{"id":441457,"data":{"date":"2025-08-11","repo":{"name":"github.com/goraz/onion","commit":"e201628c9dac0f15a5a8d368e7afb250b80394f8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.1,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":3,"reason":"Found 5/16 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'develop'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 19 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"13 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2022-0322 / GHSA-cg3q-j54f-5p7p","Warn: Project is vulnerable to: GHSA-wf43-55jj-vwq8","Warn: Project is vulnerable to: GO-2024-2528","Warn: Project is vulnerable to: GO-2024-2529","Warn: Project is vulnerable to: GO-2024-2530","Warn: Project is vulnerable to: GO-2022-0968 / GHSA-gwc9-m7rh-j2ww","Warn: Project is vulnerable to: GO-2021-0356 / GHSA-8c26-wmh5-6g9v","Warn: Project is vulnerable to: GO-2024-2961","Warn: Project is vulnerable to: GO-2023-2402 / GHSA-45x7-px36-x8w8","Warn: Project is vulnerable to: GO-2024-3321 / GHSA-v778-237x-gjrc","Warn: Project is vulnerable to: GO-2025-3487 / GHSA-hcg3-q754-cr77","Warn: Project is vulnerable to: GO-2022-0493 / GHSA-p782-xgp4-8hr8","Warn: Project is vulnerable to: GO-2023-2153 / GHSA-m425-mq94-257g / GHSA-qppj-fm5r-hxr3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T05:40:30.259Z","repository_id":35251100,"created_at":"2025-08-19T05:40:30.259Z","updated_at":"2025-08-19T05:40:30.259Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28723429,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T08:27:05.734Z","status":"ssl_error","status_checked_at":"2026-01-24T08:27:01.197Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","golang"],"created_at":"2024-07-30T20:01:11.917Z","updated_at":"2026-01-24T09:35:48.819Z","avatar_url":"https://github.com/goraz.png","language":"Go","readme":"# onion\n\n[![Build Status](https://travis-ci.org/goraz/onion.svg)](https://travis-ci.org/goraz/onion)\n[![Coverage Status](https://coveralls.io/repos/goraz/onion/badge.svg?branch=develop\u0026service=github)](https://coveralls.io/github/goraz/onion?branch=master)\n[![GoDoc](https://godoc.org/github.com/goraz/onion?status.svg)](https://godoc.org/github.com/goraz/onion)\n[![Go Report Card](https://goreportcard.com/badge/github.com/goraz/onion)](https://goreportcard.com/report/github.com/goraz/onion)\n\n    import \"github.com/goraz/onion\"\n\nPackage onion is a layer based, pluggable config manager for golang.\n\nThe current version in `develop` branch is work in progress (see the [milestone](https://github.com/goraz/onion/milestone/1)), for older versions check the `v2` and `v3` branches and use the `gopkg.in/goraz/onion.v1` and `gopkg.in/goraz/onion.v2`\nFor the next release we use the go module and tagging using semantic version.\n\n```\nShrek: For your information, there's a lot more to ogres than people think.\nDonkey: Example?\nShrek: Example... uh... ogres are like onions! \n[holds up an onion, which Donkey sniffs] \nDonkey: They stink? \nShrek: Yes... No! \nDonkey: Oh, they make you cry? \nShrek: No! \nDonkey: Oh, you leave 'em out in the sun, they get all brown, start sproutin' little white hairs...\nShrek: [peels an onion] NO! Layers. Onions have layers. Ogres have layers... You get it? We both have layers.\n[walks off]\nDonkey: Oh, you both have LAYERS. Oh. You know, not everybody like onions. CAKE! Everybody loves cake! Cakes have layers!\nShrek: I don't care what everyone likes! Ogres are not like cakes.\nDonkey: You know what ELSE everybody likes? Parfaits! Have you ever met a person, you say, \"Let's get some parfait,\" they say, \"Hell no, I don't like no parfait.\"? Parfaits are delicious!\nShrek: NO! You dense, irritating, miniature beast of burden! Ogres are like onions! End of story! Bye-bye! See ya later.\nDonkey: Parfait's gotta be the most delicious thing on the whole damn planet! \n```\n## Goals \n\nThe main goal is to have minimal dependency based on usage. if you need normal config files in the file system, \nthere should be no dependency to `etcd` or `consul`, if you have only `yaml` files, including `toml` or any other format \nis just not right.\n\n## Usage \n\nChoose the layer first. normal file layer and json are built-in but for any other type \nyou need to import the package for that layer. \n\n### Example json file layer \n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/goraz/onion\"\n)\n\nfunc main() {\n\t// Create a file layer to load data from json file. onion loads the file based on the extension.\n\t// so the json file should have `.json` ext.\n\tl1, err := onion.NewFileLayer(\"/etc/shared.json\", nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create a layer based on the environment. it loads every environment with APP_ prefix\n\t// for example APP_TEST_STRING is available as o.Get(\"test.string\")\n\tl2 := onion.NewEnvLayerPrefix(\"_\", \"APP\")\n\n\t// Create the onion, the final result is union of l1 and l2 but l2 overwrite l1.\n\to := onion.New(l1, l2)\n\tstr := o.GetStringDefault(\"test.string\", \"empty\")\n\tfmt.Println(str)\n\t// Now str is the string in this order\n\t// 1- if the APP_TEST_STRING is available in the env\n\t// 2- if the shared.json had key like this { \"test\" : { \"string\" : \"value\" }} then the str is \"value\"\n\t// 3- the provided default, \"empty\"\n}\n```\n\n### Loading other file format \n\nCurrently `onion` support `json` format out-of-the-box, while you need to blank import the loader package of others formats to use them:\n* `toml` (for 0.4.0 version)\n* `toml-0.5.0` (for 0.5.0 version)\n* `yaml`\n* `properties`\n\nFor example:\n```go \nimport (\n    _ \"github.com/goraz/onion/loaders/toml\" // Needed to load TOML format\n)\n``` \n\n### Watch file and etcd\n\nAlso there is other layers, (like `etcd` and `filewatchlayer`) that watches for change. \n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/goraz/onion\"\n\t\"github.com/goraz/onion/layers/etcdlayer\"\n\t\"github.com/goraz/onion/layers/filewatchlayer\"\n)\n\nfunc main() {\n\t// Create a file layer to load data from json file. also it watches for change in the file\n\tl1, err := filewatchlayer.NewFileWatchLayer(\"/etc/shared.json\", nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tl2, err := etcdlayer.NewEtcdLayer(\"/app/config\", \"json\", []string{\"http://127.0.0.1:2379\"}, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create the onion, the final result is union of l1 and l2 but l2 overwrite l1.\n\to := onion.New(l1, l2)\n\t// Get the latest version of the key \n\tstr := o.GetStringDefault(\"test.string\", \"empty\")\n\tfmt.Println(str)\n}\n```\n\n### Encrypted config \n\nAlso if you want to store data in encrypted content. currently only `secconf` (based on the [crypt](https://github.com/xordataexchange/crypt) project) is supported.\nalso the [onioncli](https://github.com/goraz/onion/tree/develop/cli/onioncli) helps you to manage this keys. \n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\n\t\"github.com/goraz/onion\"\n\t\"github.com/goraz/onion/ciphers/secconf\"\n\t\"github.com/goraz/onion/layers/etcdlayer\"\n\t\"github.com/goraz/onion/layers/filewatchlayer\"\n)\n\n// Normally this should be in a safe place, not here\nconst privateKey = `PRIVATE KEY`\n\nfunc main() {\n\t// The private key should be in the safe place. this is just a demo, also there is a cli tool\n\t// to create this `go get -u github.com/goraz/onion/cli/onioncli`\n\tcipher, err := secconf.NewCipher(bytes.NewReader([]byte(privateKey)))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create a file layer to load data from json file. also it watches for change in the file\n\t// passing the cipher to this make means the file in base64 and pgp encrypted\n\tl1, err := filewatchlayer.NewFileWatchLayer(\"/etc/shared.json\", cipher)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create a etcd layer. it watches the /app/config key and it should be json file encoded with\n\t// base64 and pgp\n\tl2, err := etcdlayer.NewEtcdLayer(\"/app/config\", \"json\", []string{\"http://127.0.0.1:2379\"}, cipher)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create the onion, the final result is union of l1 and l2 but l2 overwrites l1.\n\to := onion.New(l1, l2)\n\t// Get the latest version of the key\n\tstr := o.GetStringDefault(\"test.string\", \"empty\")\n\tfmt.Println(str)\n}\n```\n","funding_links":[],"categories":["Configuration","配置","Uncategorized","Go"],"sub_categories":["Standard CLI","标准CLI","Advanced Console UIs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoraz%2Fonion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoraz%2Fonion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoraz%2Fonion/lists"}