Documentation ¶
Overview ¶
Package vcard implements the vCard format, defined in RFC 6350.
Index ¶
- Constants
- func ToV4(card Card)
- type Address
- type Card
- func (c Card) Add(k string, f *Field)
- func (c Card) AddAddress(address *Address)
- func (c Card) AddName(name *Name)
- func (c Card) AddValue(k, v string)
- func (c Card) Address() *Address
- func (c Card) Addresses() []*Address
- func (c Card) Categories() []string
- func (c Card) FormattedNames() []*Field
- func (c Card) Gender() (sex Sex, identity string)
- func (c Card) Get(k string) *Field
- func (c Card) Kind() Kind
- func (c Card) Name() *Name
- func (c Card) Names() []*Name
- func (c Card) Preferred(k string) *Field
- func (c Card) PreferredValue(k string) string
- func (c Card) Revision() (time.Time, error)
- func (c Card) Set(k string, f *Field)
- func (c Card) SetAddress(address *Address)
- func (c Card) SetCategories(categories []string)
- func (c Card) SetGender(sex Sex, identity string)
- func (c Card) SetKind(kind Kind)
- func (c Card) SetName(name *Name)
- func (c Card) SetRevision(t time.Time)
- func (c Card) SetValue(k, v string)
- func (c Card) Value(k string) string
- func (c Card) Values(k string) []string
- type Decoder
- type Encoder
- type Field
- type Kind
- type Name
- type Params
- type Sex
Examples ¶
Constants ¶
const ( MIMEType = "text/vcard" Extension = "vcf" )
MIME type and file extension for VCard, defined in RFC 6350 section 10.1.
const ( ParamLanguage = "LANGUAGE" ParamValue = "VALUE" ParamPreferred = "PREF" ParamAltID = "ALTID" ParamPID = "PID" ParamType = "TYPE" ParamMediaType = "MEDIATYPE" ParamCalendarScale = "CALSCALE" ParamSortAs = "SORT-AS" ParamGeolocation = "GEO" ParamTimezone = "TZ" )
Card property parameters.
const ( // General Properties FieldSource = "SOURCE" FieldKind = "KIND" FieldXML = "XML" // Identification Properties FieldFormattedName = "FN" FieldName = "N" FieldNickname = "NICKNAME" FieldPhoto = "PHOTO" FieldBirthday = "BDAY" FieldAnniversary = "ANNIVERSARY" FieldGender = "GENDER" // Delivery Addressing Properties FieldAddress = "ADR" // Communications Properties FieldTelephone = "TEL" FieldEmail = "EMAIL" FieldIMPP = "IMPP" // Instant Messaging and Presence Protocol FieldLanguage = "LANG" // Geographical Properties FieldTimezone = "TZ" FieldGeolocation = "GEO" // Organizational Properties FieldTitle = "TITLE" FieldRole = "ROLE" FieldLogo = "LOGO" FieldOrganization = "ORG" FieldMember = "MEMBER" FieldRelated = "RELATED" // Explanatory Properties FieldCategories = "CATEGORIES" FieldNote = "NOTE" FieldProductID = "PRODID" FieldRevision = "REV" FieldSound = "SOUND" FieldUID = "UID" FieldClientPIDMap = "CLIENTPIDMAP" FieldURL = "URL" FieldVersion = "VERSION" // Security Properties FieldKey = "KEY" // Calendar Properties FieldFreeOrBusyURL = "FBURL" FieldCalendarAddressURI = "CALADRURI" FieldCalendarURI = "CALURI" )
Card properties.
const ( // Generic TypeHome = "home" TypeWork = "work" // For FieldTelephone TypeText = "text" TypeVoice = "voice" // Default TypeFax = "fax" TypeCell = "cell" TypeVideo = "video" TypePager = "pager" TypeTextPhone = "textphone" // For FieldRelated TypeContact = "contact" TypeAcquaintance = "acquaintance" TypeFriend = "friend" TypeMet = "met" TypeCoWorker = "co-worker" TypeColleague = "colleague" TypeCoResident = "co-resident" TypeNeighbor = "neighbor" TypeChild = "child" TypeParent = "parent" TypeSibling = "sibling" TypeSpouse = "spouse" TypeKin = "kin" TypeMuse = "muse" TypeCrush = "crush" TypeDate = "date" TypeSweetheart = "sweetheart" TypeMe = "me" TypeAgent = "agent" TypeEmergency = "emergency" )
Values for ParamType.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Address ¶
type Address struct { *Field PostOfficeBox string ExtendedAddress string // e.g., apartment or suite number StreetAddress string Locality string // e.g., city Region string // e.g., state or province PostalCode string Country string }
An Address is a delivery address.
type Card ¶
A Card is an address book entry.
func (Card) AddAddress ¶
AddAddress adds an address to the list of addresses.
func (Card) AddValue ¶
AddValue adds the k, v pair to the list of field values. It appends to any existing values.
func (Card) Address ¶
Address returns the preferred address of the card. If it isn't specified, it returns nil.
func (Card) Categories ¶
Categories returns category information about the card, also known as "tags".
func (Card) FormattedNames ¶
FormattedNames returns formatted names of the card. The length of the result is always greater or equal to 1.
func (Card) Get ¶
Get returns the first field of the card for the given property. If there is no such field, it returns nil.
func (Card) Kind ¶
Kind returns the kind of the object represented by this card. If it isn't specified, it returns the default: KindIndividual.
func (Card) Name ¶
Name returns the preferred name of the card. If it isn't specified, it returns nil.
func (Card) PreferredValue ¶
PreferredValue returns the preferred field value of the card.
func (Card) SetAddress ¶
SetAddress replaces the list of addresses with the single specified address.
func (Card) SetCategories ¶
SetCategories sets category information about the card.
func (Card) SetRevision ¶
SetRevision sets revision information about the current card.
func (Card) SetValue ¶
SetValue sets the field k to the single value v. It replaces any existing value.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder parses cards.
func NewDecoder ¶
NewDecoder creates a new Decoder reading cards from an io.Reader.
Example ¶
f, err := os.Open("cards.vcf") if err != nil { log.Fatal(err) } defer f.Close() dec := vcard.NewDecoder(f) for { card, err := dec.Decode() if err == io.EOF { break } else if err != nil { log.Fatal(err) } log.Println(card.PreferredValue(vcard.FieldFormattedName)) }
Output:
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder formats cards.
func NewEncoder ¶
NewEncoder creates a new Encoder that writes cards to w.
Example ¶
destFile, err := os.Create("cards.vcf") if err != nil { log.Fatal(err) } defer destFile.Close() // data in order: first name, middle name, last name, telephone number contacts := [][4]string{ {"John", "Webber", "Maxwell", "(+1) 199 8714"}, {"Donald", "", "Ron", "(+44) 421 8913"}, {"Eric", "E.", "Peter", "(+37) 221 9903"}, {"Nelson", "D.", "Patrick", "(+1) 122 8810"}, } var ( // card is a map of strings to []*vcard.Field objects card = make(vcard.Card) // destination where the vcard will be encoded to enc = vcard.NewEncoder(destFile) ) for _, entry := range contacts { // set only the value of a field by using card.SetValue. // This does not set parameters card.SetValue(vcard.FieldFormattedName, strings.Join(entry[:3], " ")) card.SetValue(vcard.FieldTelephone, entry[3]) // set the value of a field and other parameters by using card.Set card.Set(vcard.FieldName, &vcard.Field{ Value: strings.Join(entry[:3], ";"), Params: map[string][]string{ vcard.ParamSortAs: []string{ entry[0] + " " + entry[2], }, }, }) // make the vCard version 4 compliant vcard.ToV4(card) err := enc.Encode(card) if err != nil { log.Fatal(err) } }
Output:
type Name ¶
type Name struct { *Field FamilyName string GivenName string AdditionalName string HonorificPrefix string HonorificSuffix string }
Name contains an object's name components.
type Params ¶
Params is a set of field parameters.
func (Params) Add ¶
Add adds the k, v pair to the list of parameters. It appends to any existing values.
func (Params) Get ¶
Get returns the first value with the key k. It returns an empty string if there is no such value.