tagparser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package tagparser provides a high-performance struct tag parser for grove:"..." and bun:"..." tags. It extracts column names, boolean options, and key:value pairs from comma-separated tag strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tag

type Tag struct {
	Name    string            // Column name or empty
	Options map[string]string // Key-value options (e.g., "pk" -> "", "type" -> "jsonb", "privacy" -> "pii")
}

Tag represents a parsed struct tag.

func Parse

func Parse(tag string) Tag

Parse parses a raw struct tag value like "column_name,pk,notnull,type:jsonb,default:'active'" into a Tag. It handles:

  • First non-option token is the column name
  • Boolean options like "pk", "notnull", "autoincrement" -> key="pk" value=""
  • Key:value options like "type:jsonb", "privacy:pii" -> key="type" value="jsonb"
  • Quoted values like "default:'hello world'" -> key="default" value="hello world"
  • Table-level options like "table:users,alias:u"

func (Tag) GetOption

func (t Tag) GetOption(key string) string

GetOption returns the value of a named option, or empty string.

func (Tag) HasOption

func (t Tag) HasOption(key string) bool

HasOption checks if a tag has a specific option.

Jump to

Keyboard shortcuts

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