{"id":17988540,"url":"https://github.com/heyvito/uyaml","last_synced_at":"2025-03-25T22:33:51.771Z","repository":{"id":57632630,"uuid":"412071618","full_name":"heyvito/uyaml","owner":"heyvito","description":"Unstructured YAML helper for Go","archived":false,"fork":false,"pushed_at":"2022-02-16T19:03:51.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"trunk","last_synced_at":"2025-03-20T22:03:54.000Z","etag":null,"topics":["editor","golang","path","selector","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heyvito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-30T13:15:40.000Z","updated_at":"2022-09-26T09:32:14.000Z","dependencies_parsed_at":"2022-08-31T13:01:17.115Z","dependency_job_id":null,"html_url":"https://github.com/heyvito/uyaml","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fuyaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fuyaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fuyaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fuyaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heyvito","download_url":"https://codeload.github.com/heyvito/uyaml/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245556286,"owners_count":20634876,"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":["editor","golang","path","selector","yaml"],"created_at":"2024-10-29T19:11:57.561Z","updated_at":"2025-03-25T22:33:51.517Z","avatar_url":"https://github.com/heyvito.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uyaml\n\nPackage **uyaml** provides utilities for working with unstructured yaml documents.\nIt allows structures to be queried, modified, and removed using a small query\nlanguage that somewhat resembles CSS selectors (in some parallel dimension).\n\nThis package is considered of beta quality, and may behave oddly in some edge\ncases. In case this happens, please file an issue to the corresponding\nrepository.\n\n## Querying Values\n\nLet's suppose you have a extensive YAML document with a key nested under some\ncomplicated hierarchy. One option is to implement structures matching the\ndocument's, so `yaml.Unmarshal` can do its job. The other option is to unmarshal\ninto a map of interfaces, or slice of interfaces. uyaml implements two methods\nto handle this scenario: `DigItem` and `MustDigItem`. For example, consider the\nfollowing YAML document:\n\n```yaml\nuserCount: 2\nusers:\n- name: josie\n  roles:\n  - bot\n  - foo\n  - bar\n- name: lester\n  roles:\n  - dummy\n```\n\nIn order to obtain roles for a user under the key `josie`, `DigItem` can be used:\n\n```go\ndoc, err := uyaml.Decode(...)\nif err != nil {\n    ...\n}\nok, item, err := doc.DigItem(\"users.(name='josie').roles\")\nif err != nil {\n\t...\n}\nif !ok {\n\t...\n}\n\nstr, ok := item.String()\nif ok {\n    fmt.Printf(\"%#v\", item.)\n}\n```\n\n`MustDigItem` works just like `DigItem`, except it only have a single return \nvalue, and panics in case the item cannot be found or the provided path cannot \nbe parsed.\n\n## Removing Values\n\nRemoving values can be done with the `Remove` method, which takes a single path\nto be removed. In case the path does not exist, a noop happens and the same\nobject is returned.\n\n```go\ndoc, err := uyaml.Decode(...)\nif err != nil {\n...\n}\ndoc, err := doc.Remove(\"users.(name='josie')\")\n```\n\n## Setting Values\n\n`Set` can be used to inject arbitrary values into the document's structure. For\ninstance (errors checking omitted for brevity):\n\n```go\n\tval, err := data.Set(\"users.(name='dummy').test\", true)\n\tyam, err := val.Encode()\n\tfmt.Println(yam)\n```\n\nWould print the following structure:\n\n ```yaml\n\tuserCount: 2\n\tusers:\n\t- name: josie\n\t  roles:\n\t  - bot\n\t  - foo\n\t  - bar\n\t- name: lester\n\t  roles:\n\t  - dummy\n\t- name: dummy\n\t  test: true\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2021 Victor Gama de Oliveira\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyvito%2Fuyaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheyvito%2Fuyaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyvito%2Fuyaml/lists"}