{"id":16813903,"url":"https://github.com/wolfogre/gtag","last_synced_at":"2025-06-11T14:02:57.348Z","repository":{"id":41497223,"uuid":"260423712","full_name":"wolfogre/gtag","owner":"wolfogre","description":"Help you to get golang struct's tags elegantly.","archived":false,"fork":false,"pushed_at":"2023-11-15T10:32:55.000Z","size":409,"stargazers_count":22,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T01:52:41.658Z","etag":null,"topics":["go","golang","tag","tags"],"latest_commit_sha":null,"homepage":"https://blog.wolfogre.com/posts/gtag/","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/wolfogre.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":"2020-05-01T09:38:27.000Z","updated_at":"2025-03-11T06:27:43.000Z","dependencies_parsed_at":"2024-06-19T04:12:14.861Z","dependency_job_id":"f3dc3a96-a88f-4cba-a9c0-1693aab4172e","html_url":"https://github.com/wolfogre/gtag","commit_stats":null,"previous_names":["gochore/tag"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfogre%2Fgtag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfogre%2Fgtag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfogre%2Fgtag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfogre%2Fgtag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wolfogre","download_url":"https://codeload.github.com/wolfogre/gtag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wolfogre%2Fgtag/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259279267,"owners_count":22833409,"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","tag","tags"],"created_at":"2024-10-13T10:28:10.955Z","updated_at":"2025-06-11T14:02:57.293Z","avatar_url":"https://github.com/wolfogre.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gtag\n\n\u003cimg src=\"./assets/gtag.png\" width=\"130\" alt=\"gtag logo\"\u003e\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/wolfogre/gtag.svg)](https://pkg.go.dev/github.com/wolfogre/gtag)\n[![Actions](https://github.com/wolfogre/gtag/actions/workflows/test.yaml/badge.svg)](https://github.com/wolfogre/gtag/actions)\n[![Codecov](https://codecov.io/gh/wolfogre/gtag/branch/master/graph/badge.svg)](https://codecov.io/gh/wolfogre/gtag)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wolfogre/gtag)](https://goreportcard.com/report/github.com/wolfogre/gtag)\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/wolfogre/gtag)](https://github.com/wolfogre/gtag/blob/master/go.mod)\n[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/wolfogre/gtag)](https://github.com/wolfogre/gtag/releases)\n\nHelp you to get golang struct's tags elegantly.\n\n## Quick start\n\n### 1. Define your struct\n\nA source file `user.go`:\n\n```go\npackage tutorial\n\ntype User struct {\n\tId    int    `bson:\"_id\"`\n\tName  string `bson:\"name\"`\n\tEmail string `bson:\"email\"`\n}\n```\n\n## 2. Run gtag\n\nRun\n\n```bash\ngo run github.com/wolfogre/gtag/cmd/gtag -types User -tags bson .\n```\n\nand you will get file user_tag.go:\n\n```go\n// Code generated by gtag. DO NOT EDIT.\n// See: https://github.com/wolfogre/gtag\n\n//go:generate go run github.com/wolfogre/gtag/cmd/gtag -types User -tags bson .\npackage tutorial\n\nimport (\n\t\"reflect\"\n\t\"strings\"\n)\n\nvar (\n\t// ...\n)\n\n// UserTags indicate tags of type User\ntype UserTags struct {\n\tId    string // `bson:\"_id\"`\n\tName  string // `bson:\"name\"`\n\tEmail string // `bson:\"email\"`\n}\n\n// Tags return specified tags of User\nfunc (*User) Tags(tag string, convert ...func(string) string) UserTags {\n\tconv := func(in string) string { return strings.TrimSpace(strings.Split(in, \",\")[0]) }\n\tif len(convert) \u003e 0 {\n\t\tconv = convert[0]\n\t}\n\tif conv == nil {\n\t\tconv = func(in string) string { return in }\n\t}\n\treturn UserTags{\n\t\tId:    conv(tagOfUserId.Get(tag)),\n\t\tName:  conv(tagOfUserName.Get(tag)),\n\t\tEmail: conv(tagOfUserEmail.Get(tag)),\n\t}\n}\n\n// TagsBson is alias of Tags(\"bson\")\nfunc (*User) TagsBson() UserTags {\n\tvar v *User\n\treturn v.Tags(\"bson\")\n}\n```\n\n## 3. Use it\n\nNow you can use the generated code to get tags elegantly:\n\n```go\n// update mongo document\nobj := User{}\ntags := obj.TagsBson()\n\n_, err := collection.UpdateOne(\n    ctx,\n    bson.M{tags.Id: id},\n    bson.M{\n        \"$set\", bson.M{\n            tags.Name: name,\n            tags.Email: email,\n        },\n    },\n)\n```\n\n## Project status\n\nGtag is beta and is considered feature complete.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfogre%2Fgtag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwolfogre%2Fgtag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwolfogre%2Fgtag/lists"}