fatih

structtag

Parse and modify Go struct field tags

by fatih

Go

Go100%

Commit activity

Last 12 weeks · 0 commits

Full graph →

Community health

2 of 6 standards met

Community profile →
42
✓README✓License○Contributing○Code of Conduct○Issue Template○PR Template

Recent PRs & issues

Quiet · 6 in progress · Last activity 3y ago
See all on GitHub →
AdamMagued

Fixes #21. Summary When parsing struct tag values, Parse() previously used strings.Split(value, ","). This unconditionally split tag values on any comma, breaking options that contained escaped commas (such as regular expressions or descriptive text like description=A reason\, hopefully a valid one). Changes Replaced unconditional strings.Split in Parse() with a custom split function that respects backslash-escaped commas. An odd number of preceding backslashes denotes an escaped comma, whereas an even number treats the comma as an option delimiter. Added comprehensive unit tests in TestParse and TestTags_EscapedCommas covering escaped commas in options, regex patterns, tag names, multiple escaped commas, and escaped backslashes preceding commas.

AdamMagued · 1mo ago
AdamMagued

Fixes #24. Export sentinel errors returned by Parse, Get, and Set (ErrTagNotExist, ErrKeyNotExist, ErrKeyNotSet, ErrTagSyntax, ErrTagKeySyntax, ErrTagValueSyntax, and ErrTagKeyMismatch). This allows callers to inspect errors using errors.Is(err, structtag.ErrTagNotExist) and errors.Is(err, structtag.ErrKeyNotExist) rather than string comparisons against error messages. Internal references and unexported alias identifiers (errTagNotExist, errKeyNotExist, errKeyNotSet, etc.) remain defined for backward compatibility. Unit tests verify error matching via errors.Is.

AdamMagued · 1mo ago
c-tonneslan

Closes #24. Per @fatih's note on the issue, the sentinel errors were unexported, so callers were stuck doing string-compare on the message to handle a 'tag not found' specifically. Promote them to \ and keep the lowercase names as aliases so the internal call sites compile unchanged. Lets users write: \\\

c-tonneslan · 6mo ago
romshark

chore: Upgrade gomod to Go 1.21. perf: Preallocate slice in . test: Add more tests and improve test coverage. test: Move syntax error testing to . refactor: Use github.com/stretchr/testify to simplify tests. refactor: Use black-box testing (test package with "_test" suffix). refactor: Use generic slice search function to reduce code duplication. A little more than promised, but I hope you're fine with these changes living in 1 PR (saved me time). Please let me know if you want these changes to be split across multiple PRs. resolves #24

romshark · 2y ago
Structured data for AI agents

Repository: fatih/structtag. Description: Parse and modify Go struct field tags Stars: 648, Forks: 48. Primary language: Go. Languages: Go (100%). Topics: go, structs, tags. Latest release: v1.2.0 (6y ago). Open PRs: 6, open issues: 3. Last activity: 3y ago. Community health: 42%. Top contributors: fatih, vanodevium.