Documentation
¶
Overview ¶
Package vdir implements RFC 2425 directory encoding with support for vCard and iCalendar profiles.
The directory blocks can be mapped to an arbitrary Go Value which is described in the Marshal and Unmarshal functions. In addition, the package provides conversions to/from a generalized Object representation which allows for detailed access and easier modification.
Index ¶
- Variables
- func FromObject(v interface{}, o *Object) error
- func Marshal(v interface{}) ([]byte, error)
- func ToObject(v interface{}, o *Object) error
- func Unmarshal(data []byte, v interface{}) error
- type Address
- type Alarm
- type Calendar
- type Card
- type ContentLine
- type DateTimeValue
- type Decoder
- type Encoder
- type Event
- type FreeBusy
- type IMPP
- type Journal
- type Name
- type Object
- type Person
- type Photo
- type RecurrenceRule
- type StructuredValue
- type TimeZoneInfo
- type Timezone
- type Todo
- type TypedValue
- type Value
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmpty = errors.New("Empty")
)
Functions ¶
func FromObject ¶
FromObject converts an intermediate Object into a struct.
See the documentation for Unmarshal for details about the conversion of into a Go Value.
func Marshal ¶
Marshal returns the encoding of v.
Marshal expects a struct as value v and traverses it recursively, mapping its fields to properties and component objects.
Each struct field becomes a property of the object unless the fields tag is "-" or the field is empty. The tag value is the property name, otherwise the uppercase struct field name is used.
A special field tagged with ",profile" defines the profile type of the block, for example a tag "vcard,profile" designates the struct to be of type VCARD.
Fields of type string are mapped to single values, string slices to a comma-delimited value list.
Fields that contain a struct are stored as a structured property with optional parameters and components. If a struct fields tag contains a "param" option as second value, it is stored as a parameter of the property. Untagged fields are stored as semicolon-delimited component values based on their order of appearance in the struct.
Fields that have a tag with option "objects" as second value are converted to a new inner BEGIN:PROFILE-END object block.
func ToObject ¶
ToObject converts a struct v into an intermediate Object that can be written by an encoder.
See the documentation for Marshal for details about the conversion of a Go Value.
func Unmarshal ¶
Unmarshal parses a single directory block from data and stores the result in the value pointed to by v.
To unmarshal an object into a struct, Unmarshal matches incoming object properties and components to the keys used by Marshal (either the struct field name or its tag), accepting a case-insensitive match.
A property content line can be unmarshalled into a string for a single value, a string slice for a value list (delimited by commas) or a struct for structured values. Umarshalling into a struct first maps all struct fields with tag ",param" to the respective parameter values and fills the remaining fields in their index order with the respective semicolon-delimited value components.
Types ¶
type Calendar ¶
type Calendar struct { Profile string `vdir:"vcalendar,profile"` Version string ProdId string Timezone []Timezone `vdir:"vtimezone,object"` Events []Event `vdir:"vevent,object"` ToDos []Todo `vdir:"vtodo,object"` Journals []Journal `vdir:"vjournal,object"` FreeBusy []FreeBusy `vdir:"vfreebusy,object"` }
Calendar is a iCalendar as defined in RFC 5545.
type Card ¶
type Card struct { Profile string `vdir:"vcard,profile"` Version string FormattedName string `vdir:"fn"` Name Name `vdir:"n"` NickName []string Birthday string `vdir:"bday"` Addresses []Address `vdir:"adr"` Telephones []TypedValue `vdir:"tel"` Email []TypedValue Url []TypedValue Title string Role string Org string Categories []string Note string URL string Photo Photo Rev string ProdId string Uid string XICQ string `vdir:"x-icq"` XSkype string `vdir:"x-skype"` IMPP []IMPP }
Card is a vCard as defined in RFC 6350.
type ContentLine ¶
type ContentLine struct {
Group, Name string
Params map[string]Value
Value StructuredValue
}
ContentLine is a single named line with named parameters and values.
type DateTimeValue ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads Directory Information Blocks from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
func (*Decoder) Decode ¶
Decode reads the next object and stores it in the value pointed to by v.
See the documentation for Unmarshal for details about the conversion into a Go value.
func (*Decoder) ReadContentLine ¶
func (dec *Decoder) ReadContentLine() (*ContentLine, error)
ReadContentLine reads the next content line and returns it.
func (*Decoder) ReadObject ¶
ReadObject reads the next object block and returns it.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An encoder writes Directory Information Blocks to an input stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) Encode ¶
Encode writes the encoded block of v to the stream.
See the documentation for Marshal for details about the conversion of Go values.
func (*Encoder) WriteContentLine ¶
func (enc *Encoder) WriteContentLine(cl *ContentLine) error
WriteContentLine writes a single content line to the stream.
func (*Encoder) WriteObject ¶
WriteObject writes an object to the stream.
type Event ¶
type Event struct { Profile string `vdir:"vevent,profile"` UID string DTStamp DateTimeValue Organizer Person DTStart DateTimeValue DTEnd DateTimeValue Location string Summary string Categories []string Description string Method string Status string Class string Sequence string Created string LastModified string `vdir:"last-modified"` Alarms []Alarm `vdir:",object"` RRule RecurrenceRule }
type FreeBusy ¶
type FreeBusy struct { Profile string `vdir:"vfreebusy,profile"` Organizer Person DTStart DateTimeValue DTEnd DateTimeValue FreeBusy []string `vdir:",multiple"` Url string }
type Object ¶
type Object struct { Profile string Properties []*ContentLine Objects []*Object }
Object is a generic Directory Information Block.
func (*Object) PropertyMap ¶
func (o *Object) PropertyMap() map[string][]*ContentLine
PropertyMap returns all properties indexed by their name.
type RecurrenceRule ¶
type StructuredValue ¶
type StructuredValue []Value
func (StructuredValue) GetText ¶
func (v StructuredValue) GetText() string
GetText returns the first value of the first component.
type TimeZoneInfo ¶
type TimeZoneInfo struct { TZOffsetFrom string TZOffsetTo string TZName string DTStart string RRule RecurrenceRule }
type Timezone ¶
type Timezone struct { Profile string `vdir:"vtimezone,profile"` TZId string Daylight []TimeZoneInfo `vdir:",object"` Standard []TimeZoneInfo `vdir:",object"` }