{"id":13817492,"url":"https://github.com/fatih/structtag","last_synced_at":"2025-05-14T15:06:20.065Z","repository":{"id":17313473,"uuid":"79814267","full_name":"fatih/structtag","owner":"fatih","description":"Parse and modify Go struct field tags","archived":false,"fork":false,"pushed_at":"2023-09-07T20:17:17.000Z","size":12,"stargazers_count":639,"open_issues_count":4,"forks_count":42,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-11T19:55:05.506Z","etag":null,"topics":["go","structs","tags"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fatih.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}},"created_at":"2017-01-23T14:56:21.000Z","updated_at":"2025-04-08T15:01:10.000Z","dependencies_parsed_at":"2024-01-18T03:47:23.858Z","dependency_job_id":null,"html_url":"https://github.com/fatih/structtag","commit_stats":{"total_commits":14,"total_committers":4,"mean_commits":3.5,"dds":0.2857142857142857,"last_synced_commit":"2977b8db49bbf5ae2e0ae2be55e43d2c1798fc03"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fstructtag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fstructtag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fstructtag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fstructtag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatih","download_url":"https://codeload.github.com/fatih/structtag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169035,"owners_count":22026207,"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":["go","structs","tags"],"created_at":"2024-08-04T06:00:46.216Z","updated_at":"2025-05-14T15:06:20.039Z","avatar_url":"https://github.com/fatih.png","language":"Go","readme":"# structtag [![](https://github.com/fatih/structtag/workflows/build/badge.svg)](https://github.com/fatih/structtag/actions) [![PkgGoDev](https://pkg.go.dev/badge/github.com/fatih/structtag)](https://pkg.go.dev/github.com/fatih/structtag)\n\nstructtag provides a way of parsing and manipulating struct tag Go fields. It's used by tools like [gomodifytags](https://github.com/fatih/gomodifytags). For more examples, checkout [the projects using structtag](https://pkg.go.dev/github.com/fatih/structtag?tab=importedby).\n\n# Install\n\n```bash\ngo get github.com/fatih/structtag\n```\n\n# Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"sort\"\n\n\t\"github.com/fatih/structtag\"\n)\n\nfunc main() {\n\ttype t struct {\n\t\tt string `json:\"foo,omitempty,string\" xml:\"foo\"`\n\t}\n\n\t// get field tag\n\ttag := reflect.TypeOf(t{}).Field(0).Tag\n\n\t// ... and start using structtag by parsing the tag\n\ttags, err := structtag.Parse(string(tag))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// iterate over all tags\n\tfor _, t := range tags.Tags() {\n\t\tfmt.Printf(\"tag: %+v\\n\", t)\n\t}\n\n\t// get a single tag\n\tjsonTag, err := tags.Get(\"json\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(jsonTag)         // Output: json:\"foo,omitempty,string\"\n\tfmt.Println(jsonTag.Key)     // Output: json\n\tfmt.Println(jsonTag.Name)    // Output: foo\n\tfmt.Println(jsonTag.Options) // Output: [omitempty string]\n\n\t// change existing tag\n\tjsonTag.Name = \"foo_bar\"\n\tjsonTag.Options = nil\n\ttags.Set(jsonTag)\n\n\t// add new tag\n\ttags.Set(\u0026structtag.Tag{\n\t\tKey:     \"hcl\",\n\t\tName:    \"foo\",\n\t\tOptions: []string{\"squash\"},\n\t})\n\n\t// print the tags\n\tfmt.Println(tags) // Output: json:\"foo_bar\" xml:\"foo\" hcl:\"foo,squash\"\n\n\t// sort tags according to keys\n\tsort.Sort(tags)\n\tfmt.Println(tags) // Output: hcl:\"foo,squash\" json:\"foo_bar\" xml:\"foo\"\n}\n```\n","funding_links":[],"categories":["Misc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fstructtag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatih%2Fstructtag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fstructtag/lists"}