tag

package
v1.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package tag provides utility for parsing Go struct tags that follow a comma-separated key-value option format, similar to the `json` tag known from the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tag

type Tag struct {
	Name string
	// contains filtered or unexported fields
}

Tag represents a parsed struct tag, separating the primary name from the additional options.

func Parse

func Parse(s string) *Tag

Parse takes a raw tag string (e.g., `json:opt1,opt2:val`) and separates it into the primary name and the options string.

func (*Tag) Opts

func (t *Tag) Opts() iter.Seq2[string, string]

Opts returns an iterator sequence over the tag's options.

Each element yielded is a key-value pair. If an option does not have an explicit value (e.g., "omitempty"), the value string will be empty. Keys and values are trimmed of surrounding whitespace. Values that were quoted in the source string (e.g., `key:"value"`) will have the quotes removed. Commas inside quoted values are preserved and not treated as option separators (e.g., `key:"val1,val2"` is one option).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL