Documentation ¶
Overview ¶
Package tagit/bson is a package that exports a type that can be used to add tag lists to your structs.
The tagit.Tags is designed to be used as an field in a struct (composition) like so:
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.
You will be able to use mgo/bson with this package. The type tagit.Tags knows how to be marshalled and unmarshalled to/from bson.
When using tagit.Tags you will have to initialize it with the tagit.NewTags() function.
Index ¶
- type Tags
- func (t *Tags) Add(tag string)
- func (t *Tags) All() []string
- func (t *Tags) Count() int
- func (t *Tags) GetBSON() (interface{}, error)
- func (t *Tags) Has(tag string) bool
- func (t *Tags) MarshalJSON() ([]byte, error)
- func (t *Tags) Remove(tag string)
- func (t *Tags) SetBSON(raw bson.Raw) error
- func (t *Tags) String() (res string)
- func (t *Tags) UnmarshalJSON(json []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 or bson.
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) GetBSON ¶
GetBSON is actually implementing the bson.Getter interface so this can be Marshaled into bson. This may be added to the basic tagit implementation because it doesn't require any new imports.
func (*Tags) MarshalJSON ¶
MarshalJSON to implement json.Marshaller. Returns the tags as JSON list of strings.
func (*Tags) SetBSON ¶
SetBSON is implementing the bson.Setter interface so this can be Unmarshaled from bson. To implement the Setter interface we need to import the bson package, so we can have the bson.Raw type available.
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.