Documentation
¶
Overview ¶
Package tagit is a package that exports two types that can be used to add tag lists to your structs. The first of them (tagit.Taggable) can be used as anonymous field in a struct:
type Article {
tagit.Taggable
}
The other one (tagit.Tags) is designed to be used as an field in a struct (composition) and is the prefered way of using taggit:
type Article {
Tags *tagit.Tags `json:"tags"`
}
By using tagit.Tags you will be able to use json.Marshal and json.Unmarshal on your type.
When using tagit.Tags you will have to initialize it with the tagit.NewTags() function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Taggable ¶
type Taggable struct {
// contains filtered or unexported fields
}
Taggable is a simple type that you can add as anonymous field to your struct and then tag/untag instances of your type
type Tags ¶
type Tags struct {
// contains filtered or unexported fields
}
Tags struct that holds tags and have a simple interface for working with the tags. By composing this the list of tags will be able to be marshalled/unmarshalled to/from JSON.
func NewTags ¶
NewTags is a constructor for Tags. You should initialize your tags with this function. This function can accept variable number of string agruments as an initial set of tags for the created object.
func (*Tags) All ¶
All returns all tags as a slice of strings. The order of the tags in the slice may vary between different calls.
func (*Tags) MarshalJSON ¶
MarshalJSON to implement json.Marshaller. Returns the tags as JSON list of strings.
func (*Tags) String ¶
String to implement fmt.Stringer. Return tags as comma separated list of words.
func (*Tags) UnmarshalJSON ¶
UnmarshalJSON to implement json.Unmarshaller. Expects JSON list of strings. Adds the tags to the list. Will not remove the current tags in the list.


