finds.dev

fatih/structtag

Parse and modify Go struct field tags

View on GitHub

★ 651GoNOASSERTIONupdated Sep 2023

// the take

structtag parses Go struct field tags, such as the json and xml tags on a struct field, into a list you can read, change, and write back as a string. It is the parsing layer underneath gomodifytags, so it is aimed at people writing code generation and editor tooling rather than application code that just needs a tag value at runtime.

The whole API fits in the README: Parse, Get, Set, Tags, and a sort.Interface implementation for deterministic output order. Set replaces a tag by key or appends a new one, so you can change one tag without rebuilding the string by hand. The code is two files, tags.go and tags_test.go, which makes it easy to read in one sitting. Since gomodifytags depends on it, the round-trip behavior has been exercised by a real code-editing tool and not only by its own tests.

The last push was September 2023 and the tree shows no changes since, so treat it as finished rather than maintained. Check go.mod and confirm it builds on your toolchain before depending on it. The README only covers the happy path. It says nothing about malformed input, duplicate keys, or escaped characters beyond Parse returning an error, so you will need to read tags_test.go to learn the edge cases. Options are plain strings with no typed model, so any meaning attached to an option, like omitempty or a database key flag, is your code's job to interpret.

We read the README, the directory tree and a key source file in October 2026. Nobody pays to be listed. How we judge →

search the same ground:

// at a glance

Stars
651
Forks
47
Language
Go
License
NOASSERTION
Last commit
7 Sep 2023

// nearby

If structtag isn't quite it.

All repos →