strx

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultKey is the key used for values without an explicit key.
	DefaultKey = "__default"
)

Variables

This section is empty.

Functions

func ParseTag

func ParseTag(input string, opts ...ParseOption) map[string]string

ParseTag parses a tag string into a map of key-value pairs with configurable separators. By default, it parses comma-separated key=value pairs (e.g., "contains,column=name,operator=eq"). Use ParseOption functions to customize the separator behavior.

Types

type BareValueMode

type BareValueMode int

BareValueMode defines how to treat values without a separator.

const (
	// BareAsValue treats bare values as values under DefaultKey (default behavior).
	// Example: "required,optional" → {"__default": "required"} (optional is ignored with warning).
	BareAsValue BareValueMode = iota
	// BareAsKey treats bare values as keys with empty values.
	// Example: "required,optional" → {"required": "", "optional": ""}.
	BareAsKey
)

type ParseOption

type ParseOption func(*parseConfig)

ParseOption configures the tag parser behavior.

func WithBareValueMode

func WithBareValueMode(mode BareValueMode) ParseOption

WithBareValueMode sets how to treat values without a separator.

BareAsValue (default): Treats bare values as values under DefaultKey. Only the first bare value is kept, subsequent ones are ignored with a warning. Example: ParseTag("required,optional") → {"__default": "required"} (optional ignored)

BareAsKey: Treats bare values as keys with empty values. Multiple bare values are allowed. Example: ParseTag("required,optional", WithBareValueMode(BareAsKey)) → {"required": "", "optional": ""}.

func WithPairDelimiter

func WithPairDelimiter(delimiter rune) ParseOption

WithPairDelimiter uses a single rune to separate pairs.

func WithPairDelimiterFunc

func WithPairDelimiterFunc(fn func(rune) bool) ParseOption

WithPairDelimiterFunc allows custom separator logic for complex cases.

func WithSpacePairDelimiter

func WithSpacePairDelimiter() ParseOption

WithSpacePairDelimiter is a convenient shorthand for space-separated formats commonly used in query strings and CLI arguments.

func WithValueDelimiter

func WithValueDelimiter(delimiter rune) ParseOption

WithValueDelimiter changes the key-value separator (default is '=').

Jump to

Keyboard shortcuts

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