structtag

package
v1.12.6 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCustomTag

func GetCustomTag(customize, key string) string

func ParseTagSettingIntoStruct

func ParseTagSettingIntoStruct(tagStr string, sep string, settings any, metaTag string) error

ParseTagSettingInto default sep ;

func ParseTagSettingToMap

func ParseTagSettingToMap(tagStr string, sep string) map[string]string

ParseTagSetting default sep ;

func ParseTagSettingToStruct

func ParseTagSettingToStruct[T any](tagStr string, sep string, metaTag string) (*T, error)

Types

type StructTag

type StructTag string

func (StructTag) Lookup

func (tag StructTag) Lookup(key string) (value string, ok bool)

type Tag

type Tag struct {
	// Key is the tag key, such as json, xml, etc..
	// i.e: `json:"foo,omitempty". Here key is: "json"
	Key string

	// Name is a part of the value
	// i.e: `json:"foo,omitempty". Here name is: "foo"
	Name string

	// Options is a part of the value. It contains a Slice of tag options i.e:
	// `json:"foo,omitempty". Here options is: ["omitempty"]
	Options []string
}

Tag defines a single struct's string literal tag

func (*Tag) GoString

func (t *Tag) GoString() string

GoString implements the fmt.GoStringer interface

func (*Tag) HasOption

func (t *Tag) HasOption(opt string) bool

HasOption returns true if the given option is available in options

func (*Tag) String

func (t *Tag) String() string

String reassembles the tag into a valid tag field representation

func (*Tag) Value

func (t *Tag) Value() string

Value returns the raw value of the tag, i.e. if the tag is `json:"foo,omitempty", the Value is "foo,omitempty"

type Tags

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

Tags represent a set of tags from a single struct field

func Parse

func Parse(tag string) (*Tags, error)

Parse parses a single struct field tag and returns the set of tags.

func (*Tags) AddOptions

func (t *Tags) AddOptions(key string, options ...string)

AddOptions adds the given option for the given key. If the option already exists it doesn't add it again.

func (*Tags) Delete

func (t *Tags) Delete(keys ...string)

Delete deletes the tag for the given keys

func (*Tags) DeleteOptions

func (t *Tags) DeleteOptions(key string, options ...string)

DeleteOptions deletes the given options for the given key

func (*Tags) Get

func (t *Tags) Get(key string) (*Tag, error)

Get returns the tag associated with the given key. If the key is present in the tag the value (which may be empty) is returned. Otherwise the returned value will be the empty string. The ok return value reports whether the tag exists or not (which the return value is nil).

func (*Tags) Keys

func (t *Tags) Keys() []string

Tags returns a Slice of tags. The order is the original tag order unless it was changed.

func (*Tags) Len

func (t *Tags) Len() int

func (*Tags) Less

func (t *Tags) Less(i int, j int) bool

func (*Tags) Set

func (t *Tags) Set(tag *Tag) error

Set sets the given tag. If the tag key already exists it'll override it

func (*Tags) String

func (t *Tags) String() string

String reassembles the tags into a valid literal tag field representation

func (*Tags) Swap

func (t *Tags) Swap(i int, j int)

func (*Tags) Tags

func (t *Tags) Tags() []*Tag

Tags returns a Slice of tags. The order is the original tag order unless it was changed.

Jump to

Keyboard shortcuts

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