{"id":17041680,"url":"https://github.com/xlab/structwalk","last_synced_at":"2025-04-12T14:33:14.564Z","repository":{"id":57491291,"uuid":"173999230","full_name":"xlab/structwalk","owner":"xlab","description":"Battle-tested Go struct and map traversal utilities.","archived":false,"fork":false,"pushed_at":"2020-01-17T15:27:50.000Z","size":10,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T09:11:07.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/xlab.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}},"created_at":"2019-03-05T18:27:45.000Z","updated_at":"2024-11-05T04:49:26.000Z","dependencies_parsed_at":"2022-08-30T04:00:09.002Z","dependency_job_id":null,"html_url":"https://github.com/xlab/structwalk","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/xlab%2Fstructwalk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fstructwalk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fstructwalk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xlab%2Fstructwalk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xlab","download_url":"https://codeload.github.com/xlab/structwalk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581361,"owners_count":21128155,"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":[],"created_at":"2024-10-14T09:13:12.243Z","updated_at":"2025-04-12T14:33:14.543Z","avatar_url":"https://github.com/xlab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## structwalk [![Go Report Card](https://goreportcard.com/badge/github.com/xlab/structwalk)](https://goreportcard.com/report/github.com/xlab/structwalk) [![GoDoc](https://godoc.org/github.com/xlab/structwalk?status.svg)](https://godoc.org/github.com/xlab/structwalk)\n\nBattle-tested Go struct and map traversal utilities. Has been around since 2016.\n\n### FieldValue\n\nReturns a value of a field in deeply nested structs, will traverse both maps and structs.\n\n```go\nstructwalk.FieldValue(path string, in interface{}) (v interface{}, found bool)\n```\n\nExample:\n\n```golang\nvar object = struct {\n    Foo struct {\n        Bar struct {\n            Baz map[string]int\n        }\n    }\n}{}\nobject.Foo.Bar.Baz = map[string]int{\n    \"Kek\": 5,\n}\n\nvalue, found := structwalk.FieldValue(\"Foo.Bar.Baz.Kek\", object)\n// value = 5\n// found = true\n```\n\n### GetterValue\n\nA special case of `FieldValue`, that checks if for a field named `Foo`,\nthere is a method that is named `FooBytes()`. Useful to avoid allocations when accesing\nstring values that can be returned as a memory pointer instead (e.g. in \n[capnproto](https://github.com/glycerine/go-capnproto)).\n\n```go\nstructwalk.GetterValue(path string, in interface{}) (v interface{}, found bool) \n```\n\n### FieldList\n\nSimply print the list of fields of a struct, recursively.\n\n```go\nstructwalk.FieldList(in interface{}) []string\n```\n\nExample:\n\n```go\nvar object = struct {\n    Foo struct {\n        Bar struct {\n            Baz  map[string]int\n            Baz2 string\n        }\n    }\n}{}\nobject.Foo.Bar.Baz = map[string]int{\n    \"Kek\": 5,\n    \"Lol\": 4,\n}\n\nlist := structwalk.FieldList(object)\n// [\n//  \"Foo.Bar.Baz.Kek\",\n//  \"Foo.Bar.Baz.Lol\",\n//  \"Foo.Bar.Baz2\"\n// ]\n```\n\n### GetterList\n\nReturns list of getter methods that accept no arguments (except the implicit pointer to the struct) and return one value. Can be used in templates to get a value that is not accessible by a method.\n\n```go\nstructwalk.GetterList(in interface{}) []string\n```\n\nExample:\n\n```go\ntype SomeDecorated struct{}\n\nfunc (s SomeDecorated) Foo() string {\n    return \"foo\"\n}\n\nfunc (s SomeDecorated) FooBytes() []byte {\n    return []byte(\"foo\")\n}\n\nfunc (s SomeDecorated) Bar() SomeStruct {\n    return SomeStruct{}\n}\n\nlist := structwalk.FieldList(SomeDecorated{})\n// [\n//   \"Bar.Baz\",\n//   \"Foo\",\n//   \"FooBytes\"\n// ]\n```\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlab%2Fstructwalk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxlab%2Fstructwalk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxlab%2Fstructwalk/lists"}