structured

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateKeysMode

type DuplicateKeysMode int
const (
	// DuplicateKeysIgnore skips silently duplicate keys.
	DuplicateKeysIgnore DuplicateKeysMode = iota

	// DuplicateKeysDeny throws an error when duplicate keys are found.
	DuplicateKeysDeny

	// DuplicateKeysAllow NOT RECOMMENDED: this does not follow the struct tag conventions.
	DuplicateKeysAllow
)

type Entry

type Entry struct {
	Key      string
	RawValue string
	// contains filtered or unexported fields
}

Entry represents a struct tag entry. An entry is composed of a key and a value.

func (*Entry) String

func (e *Entry) String() string

String returns the string representation of the entry.

func (*Entry) Values

func (e *Entry) Values() (TagValues, error)

Values returns the values of the entry. When modifying the values, the result must be set [Entry.RawValue].

type Filler

type Filler struct {
	// contains filtered or unexported fields
}

Filler fills the tag from a struct tag.

func NewFiller

func NewFiller(escapeComma bool, duplicateKeysMode DuplicateKeysMode) *Filler

NewFiller creates a new Filler.

func (*Filler) Data

func (f *Filler) Data() *Tag

Data returns the Tag filled by the struct tag content.

func (*Filler) Fill

func (f *Filler) Fill(key, value string) error

Fill fills the data from a struct tag.

type Option

type Option func(*config)

func WithDuplicateKeysMode

func WithDuplicateKeysMode(mode DuplicateKeysMode) Option

func WithEscapeComma

func WithEscapeComma() Option

type Tag

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

Tag represents a struct tag.

func NewTag

func NewTag(escapeComma bool, duplicateKeysMode DuplicateKeysMode) *Tag

NewTag creates a new Tag.

func Parse

func Parse(tag string, options ...Option) (*Tag, error)

Parse parses a struct tag to a Tag. Allows modifying the struct tags. The value is split on comma. Ignore duplicated keys by default.

func (*Tag) Add

func (t *Tag) Add(tag *Entry) error

Add adds a new entry to the Tag.

func (*Tag) Delete

func (t *Tag) Delete(key string)

Delete deletes the entry with the given key.

func (*Tag) Get

func (t *Tag) Get(key string) *Entry

Get returns the first entry with the given key.

func (*Tag) GetAll

func (t *Tag) GetAll(key string) []*Entry

GetAll returns all entries with the given key. NOT RECOMMENDED TO USE IT: this does not follow the struct tag conventions.

func (*Tag) IsEmpty

func (t *Tag) IsEmpty() bool

IsEmpty returns true if the Tag is empty.

func (*Tag) Seq

func (t *Tag) Seq() iter.Seq[*Entry]

Seq returns a sequence of entries.

func (*Tag) Sort

func (t *Tag) Sort()

Sort sorts the entries alphabetically by key.

func (*Tag) String

func (t *Tag) String() string

String returns the string representation of the Tag.

type TagValues

type TagValues []string

TagValues is a slice of values related to a key.

func (TagValues) Has

func (t TagValues) Has(value string) bool

Has checks if the values contain the given value.

func (TagValues) IsEmpty

func (t TagValues) IsEmpty() bool

IsEmpty returns true if the values are empty.

func (TagValues) String

func (t TagValues) String() string

String returns the string representation of the values.

Jump to

Keyboard shortcuts

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