Tag is a lightweight, zero-dependency library that transforms raw Go struct tag strings into strongly typed, well-structured Go values.
It eliminates repetitive parsing logic, reduces boilerplate, and provides a clean, declarative way to define your tag schema — while keeping performance predictable and implementation overhead minimal.
To install Tag, run the following command:
go get go.codnect.io/tagGo’s reflect.StructTag exposes tag values only as raw strings:
prop:"'database.host',default=5432"In most projects, this leads to manual string splitting, repetitive parsing logic, custom flag handling, default value handling, and edge cases around typed values. Tag centralizes this logic into a declarative schema. You define a struct that describes your tag, and Tag handles parsing, type inference, nested structures, and value assignment.
Define the structure of your tag and implement the Tagger interface:
type PropTag struct {
Key string `option:"value"`
Optional bool `option:"optional"`
Default int `option:"default"`
}
// Tag identifies the tag name.
func (t PropTag) Tag() string {
return "prop"
}Parse a raw tag string:
propTag := &PropTag{}
err := tag.Parse(`prop:"'database.host',default=5432"`, propTag)
if err != nil {
// handle error
}- Primary values with option:"value"
- Boolean flags such as optional
- Key/value options such as default=5432
- Primitive values, slices, maps, and nested structs
- Typed binding into your own schema structs
Read the full documentation at go.codnect.io/tag.
Tag is released under version 2.0 of the Apache License.
