{"id":22506430,"url":"https://github.com/a-poor/tags","last_synced_at":"2025-03-27T23:40:50.051Z","repository":{"id":57632829,"uuid":"412628350","full_name":"a-poor/tags","owner":"a-poor","description":"Go struct tags helper library","archived":false,"fork":false,"pushed_at":"2021-10-02T16:39:35.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T06:36:00.168Z","etag":null,"topics":["go","golang","reflect","struct","struct-tags","tags"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/a-poor/tags","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/a-poor.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":"2021-10-01T22:03:35.000Z","updated_at":"2021-10-02T16:37:59.000Z","dependencies_parsed_at":"2022-08-31T13:20:47.749Z","dependency_job_id":null,"html_url":"https://github.com/a-poor/tags","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/a-poor%2Ftags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-poor%2Ftags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-poor%2Ftags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-poor%2Ftags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-poor","download_url":"https://codeload.github.com/a-poor/tags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245944060,"owners_count":20697946,"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","golang","reflect","struct","struct-tags","tags"],"created_at":"2024-12-07T00:43:43.574Z","updated_at":"2025-03-27T23:40:50.032Z","avatar_url":"https://github.com/a-poor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tags\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/a-poor/tags.svg)](https://pkg.go.dev/github.com/a-poor/tags)\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/a-poor/tags?style=flat-square)](https://pkg.go.dev/github.com/a-poor/tags)\n[![Go Test](https://github.com/a-poor/tags/actions/workflows/go.yml/badge.svg)](https://github.com/a-poor/tags/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/a-poor/tags)](https://goreportcard.com/report/github.com/a-poor/tags)\n[![GitHub](https://img.shields.io/github/license/a-poor/tags?style=flat-square)](https://github.com/a-poor/tags/blob/main/LICENSE)\n![GitHub last commit](https://img.shields.io/github/last-commit/a-poor/tags?style=flat-square)\n[![Sourcegraph](https://sourcegraph.com/github.com/a-poor/tags/-/badge.svg)](https://sourcegraph.com/github.com/a-poor/tags?badge)\n[![CodeFactor](https://www.codefactor.io/repository/github/a-poor/tags/badge/main)](https://www.codefactor.io/repository/github/a-poor/tags/overview/main)\n\n\n_created by Austin Poor_\n\nA micro-helper-library for working with Go struct tags.\n\n## Installation\n\nInstall with `go get`:\n\n```sh\ngo get github.com/a-poor/tags\n```\n\n## Example\n\nHere's a quick example of working with the `tags` library.\n\n```go\n// Define a struct that we'll be getting the tags from\nuser := struct {\n    ID      int    `app:\"user_id\"`\n    Name    string `app:\",omitempty\"`\n    Email   string `app:\"user_email,omitempty\"`\n    NotMe   bool\n    ImEmpty bool `app:\"\"`\n}{}\n\n// Parse the struct's tags\nfields := tags.ParseStructTags(\"app\", user)\n\n// Print out the results as JSON\ndata, _ := json.MarshalIndent(fields, \"\", \"  \")\nfmt.Println(string(data))\n// Output: {\n//   \"Email\": [\n//     \"user_email\",\n//     \"omitempty\"\n//   ],\n//   \"ID\": [\n//     \"user_id\"\n//   ],\n//   \"ImEmpty\": [\n//     \"\"\n//   ],\n//   \"Name\": [\n//     \"\",\n//     \"omitempty\"\n//   ]\n// }\n```\n\n## Usage\n\nThe `tags` library is _very_ small. At least for now.\n\nThere's only one struct, `TagParser`, which has one field, `TagName`, and one method, `Parse`.\n\nSay, for example, we have a struct that looks like this:\n\n```go\ntype User struct {\n    ID       int     `myTag:\"user_id\"`\n    Name     string  `myTag:\"name\" otherTag\"abc123\"`\n    Balance  float32 `myTag:\"balance,omitempty\"`\n    IsActive bool    `myTag:\",hello\"`\n}\n```\n\nIf we wanted to get the struct tag values for `myTag`, we could create a new `TagParser` like this:\n\n```go\ntp := tags.TagParser{TagName: \"myTag\"}\n```\n\nand then parse the struct's tags like this:\n\n```go\nu := User{} // Create a blank user\nut := tp.Parse(u)\n```\n\n`ut` is of the type `map[string][]string`, where each of the map's keys are fields of the struct (with tags), and the map's values are arrays of tag values corresponding to the chosen tag, split on commas.\n\nIn our example, we would have the following result (formatted as JSON):\n\n```json\n{\n  \"Balance\": [\n    \"balance\",\n    \"omitempty\"\n  ],\n  \"ID\": [\n    \"user_id\"\n  ],\n  \"IsActive\": [\n    \"\",\n    \"hello\"\n  ],\n  \"Name\": [\n    \"name\"\n  ]\n}\n```\n\n## To Do\n\n- Should untagged fields appear in the returned result?\n- Add more error checks \n  - ie Catch panics caused by `tags` and return them rather than letting the panic propagate\n  - Check that the passed value is a struct (not a basic type)\n- Be able to pass a pointer to a struct (without panicing)\n- Fill a struct with struct tag values? \n  - ie struct would have fields `name`, `omitempty`, etc. and would be filled by position or value (like flags).\n\n## License\n\n[MIT](./LICENSE)\n\n## Contributing\n\nGo ahead and create an issue or submit a pull request! I'd love to hear from you.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-poor%2Ftags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-poor%2Ftags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-poor%2Ftags/lists"}