strhelpers

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 4 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 added in v0.11.0

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 added in v0.11.0

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 added in v0.11.0

type ParseOption func(*parseConfig)

ParseOption configures the tag parser behavior.

func WithBareValueMode added in v0.11.0

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 added in v0.11.0

func WithPairDelimiter(delimiter rune) ParseOption

WithPairDelimiter uses a single rune to separate pairs.

func WithPairDelimiterFunc added in v0.11.0

func WithPairDelimiterFunc(fn func(rune) bool) ParseOption

WithPairDelimiterFunc allows custom separator logic for complex cases.

func WithSpacePairDelimiter added in v0.11.0

func WithSpacePairDelimiter() ParseOption

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

func WithValueDelimiter added in v0.11.0

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