Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tag-logo

Tag — Declarative Struct Tag Parser for Go

Run Tests Quality Gate Status Coverage Go Reference

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.

Installation

To install Tag, run the following command:

go get go.codnect.io/tag

Overview

Go’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.

Quick Start

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
}

What it supports

  • 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

Documentation

Read the full documentation at go.codnect.io/tag.

License

Tag is released under version 2.0 of the Apache License.

About

Declarative Struct Tag Parser for Go

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages