tags

package
v4.1.12+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const PATHSEP = ":"
View Source
const TAGCHARS = PATHSEP + "a-zA-Z0-9._-"
View Source
const TAGSEPS = ", "

Variables

This section is empty.

Functions

func GenerateFlatMap

func GenerateFlatMap(tags Tags, only []string) map[string][]string

GenerateFlatMap takes a list of tags and transforms it into a map of string to array of string, where the map is keyed by the first element of each of the tags (before the first colon). The 'only' parameter limits the output to only the set of tags specified in only. If only is blank or contains a single empty string, then all tags are included.

func ParseTag

func ParseTag(input string) error

ParseTag takes a single string and validates it as a single tag; returns error if it fails.

func UnmarshalTags

func UnmarshalTags(ts Tags, output interface{}) error

UnmarshalTags accepts a Tags array and moves the data into a struct that is passed in as a pointer to the output object. Unmarshaling is controlled by the tags struct tag, very similar to the json.Unmarshal command. It supports unmarshaling data into bool, int, string, and []string fields.

Types

type TagInfo

type TagInfo struct {
	Name   string
	Fields map[string]string
}

func NewTagInfo

func NewTagInfo(tagdata string) TagInfo

func (TagInfo) GetTag

func (ti TagInfo) GetTag(k string) string

func (TagInfo) GetTagForInt

func (ti TagInfo) GetTagForInt(i int) string

func (TagInfo) GetValue

func (ti TagInfo) GetValue(val string) string

func (TagInfo) GetValueAsInt

func (ti TagInfo) GetValueAsInt(val string) (int, error)

type Tags

type Tags []string

Tags is a type that's just an []string but it helps us to define a couple of helper functions on it

func MarshalTags

func MarshalTags(v interface{}) (Tags, error)

func MarshalTagsX added in v1.2.0

func MarshalTagsX(v interface{}, tagstag string) (Tags, error)

MarshalTags returns the struct as Tags[]

MarshalTags traverses v looking for fields with a structure tag called tags, and interprets it to store values in the TagMap

func ParseTags

func ParseTags(input string) (tags Tags, err error)

ParseTags takes an input string, validates it, and returns a list of unique tags

func (Tags) Get added in v1.2.0

func (tags Tags) Get(key string) string

Get retrieves the portion of a tag after the colon after matching the part before the colon. If there are multiple values, it returns the first one

func (Tags) Has

func (tags Tags) Has(s string) bool

Has identifies whether a set of tags has a particular value present

func (Tags) RemoveDups

func (tags Tags) RemoveDups() Tags

RemoveDups removes duplicate entries in the list of tags

Jump to

Keyboard shortcuts

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