go_ical

package module
v0.0.0-...-fa973b3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 10 Imported by: 0

README

go-ical

RFC 5545 implements in Go

Documentation

Index

Examples

Constants

View Source
const (
	Paramaltrep         = "ALTREP"
	Paramcn             = "CN"
	Paramcutype         = "CUTYPE"
	Paramdelfrom        = "DELEGATED-FROMx"
	Paramdelto          = "DELEGATED-TO"
	Paramdir            = "DIR"
	Paramencoding       = "ENCODING"
	Paramfmttype        = "FMTTYPE"
	Paramfbtype         = "FBTYPE"
	Paramlanguage       = "LANGUAGE"
	Parammember         = "MEMBER"
	Parampartstat       = "PARTSTAT"
	Paramrange          = "RANGE"
	Paramtrigrel        = "RELATED"
	Paramreltype        = "RELTYPE"
	Paramrole           = "ROLE"
	Paramrsvp           = "RSVP"
	Paramsentby         = "SENT-BY"
	Paramtzid           = "TZID"
	Paramvaluetypeparam = "VALUE"
)

Parameters defined in RFC 5545 3.2

View Source
const (
	VDTdefault         = ""
	VDTbinary          = "BINARY"
	VDTbool            = "BOOL"
	VDTcalendaraddress = "CAL-ADDRESS"
	VDTdate            = "DATE"
	VDTdatetime        = "DATE-TIME"
	VDTduration        = "DURATION"
	VDTfloat           = "FLOAT"
	VDTint             = "INTEGER"
	VDTperiod          = "PERIOD"
	VDTrecurrence      = "RECUR"
	VDTtext            = "TEXT"
	VDTtime            = "TIME"
	VDTuri             = "URI"
	VDTutcoffset       = "UTC-OFFSET"
)

Value types defined in RFC 5545 3.3

View Source
const (
	PropCalendarScale     = "CALSCALE"
	PropMethod            = "METHOD"
	PropProductIdentifier = "PRODID"
	PropVersion           = "VERSION"
)

propertis defined in RFC 5545 3.7

View Source
const (
	//Descriptive Component Properties
	PropAttachment         = "ATTACH"
	PropCategories         = "CATEGORIES"
	PropClassification     = "CLASS"
	PropComment            = "COMMENT"
	PropDescription        = "DESCRIPTION"
	PropGeographicPosition = "GEO"
	PropLocation           = "LOCATION"
	PropPercentComplete    = "PERCENT-COMPLETE"
	PropPriority           = "PRIORITY"
	PropResources          = "RESOURCES"
	PropStatus             = "STATUS"
	PropSummary            = "SUMMARY"

	//Date and Time Component Properties
	PropDatetimeCompleted = "COMPLETED"
	PropDatetimeEnd       = "DTEND"
	PropDatetimeDue       = "DUE"
	PropDatetimeStart     = "DTSTART"
	PropDuration          = "DURATION"
	PropFreeBusy          = "FREEBUSY"
	PropTimeTransparency  = "TRANSP"

	//Time Zone Component Properties
	PropTimeZoneIdentifier = "TZID"
	PropTimeZoneName       = "TZNAME"
	PropTimeZoneOffsetFrom = "TZOFFSETFROM"
	PropTimeZoneOffsetTo   = "TZOFFSETTO"
	PropTimeZoneURL        = "TZURL"

	//Relationship Component Properties
	PropAttendee     = "ATTENDEE"
	PropContact      = "CONTACT"
	PropOrganizer    = "ORGANIZER"
	PropRecurrenceId = "RECURRENCE-ID"
	PropRelatedTo    = "RELATED-TO"
	PropURL          = "URL"
	PropUID          = "UID"

	//Recurrence Component Properties
	PropExceptionDatetime  = "EXDATE"
	PropRecurrenceDatetime = "RDATE"
	PropRecurrenceRule     = "RRULE"

	//Alarm Component Properties
	PropAction      = "ACTION"
	PropRepeatCount = "REPEAT"
	PropTrigger     = "TRIGGER"

	//Change Management Component Properties
	PropDatetimeCreated = "CREATED"
	PropDatetimeStamp   = "DTSTAMP"
	PropLastModified    = "LAST-MODIFIED"
	PropSequenceNumber  = "SEQUENCE"

	//Request Status
	PropRequestStatus = "REQUEST-STATUS"
)

component properties defined in RFC 3.8

View Source
const (
	DateFormat      = "20060102"
	DatetimeFormat  = "20060102T150405"
	DatetimeFormat2 = "20060102T150405Z"
)
View Source
const (
	CompCalendar         = "VCALENDAR"
	CompEvent            = "VEVENT"
	CompTodo             = "VTODO"
	CompJournal          = "VJOURNAL"
	CompFreebusy         = "VFREEBUSY"
	CompTimezone         = "VTIMEZONE"
	CompTimezoneStandard = "STANDARD"
	CompTimezoneDaylight = "DAYLIGHT"
	CompAlarm            = "VALARM"
)

RFC 5545 3.6

Variables

property default vaule data type

Functions

func FromText

func FromText(s string) string

func ToText

func ToText(s string) string

Types

type Attendee

type Attendee struct {
	ComponentObj
}

type Calendar

type Calendar struct {
	ComponentObj
}

func NewCalendar

func NewCalendar() *Calendar

func (*Calendar) AddComponent

func (cal *Calendar) AddComponent(coms ...Component)

func (*Calendar) GetEvents

func (cal *Calendar) GetEvents() []Component

func (*Calendar) SetDescription

func (cal *Calendar) SetDescription(st string, pis ...ParamItem)

func (*Calendar) SetLastModified

func (cal *Calendar) SetLastModified(st string, pis ...ParamItem)

func (*Calendar) SetMethod

func (cal *Calendar) SetMethod(st string, pis ...ParamItem)

func (*Calendar) SetProductId

func (cal *Calendar) SetProductId(st string, pis ...ParamItem)

func (*Calendar) SetProperty

func (cal *Calendar) SetProperty(pname string, val string, pis ...ParamItem)

func (*Calendar) SetVersion

func (cal *Calendar) SetVersion(st string, pis ...ParamItem)

type Component

type Component interface {
	Name() string
	Properties() []Property //TODO:prepare for IANA properties   RFC 5545 8
	SubComponents() []Component
	IsAvailable() error
	// contains filtered or unexported methods
}

The value for the "component" parameter is defined as follows:

component = "VEVENT"
          / "VTODO"
          / "VJOURNAL"
          / "VFREEBUSY"
          / "VTIMEZONE"
          / iana-token
          / x-name

type ComponentObj

type ComponentObj struct {
	NameObj          string
	PropertiesObj    []Property
	SubComponentsObj []Component
}

func (*ComponentObj) IsAvailable

func (com *ComponentObj) IsAvailable() error

to check componet

func (*ComponentObj) Name

func (com *ComponentObj) Name() string

func (*ComponentObj) Properties

func (com *ComponentObj) Properties() []Property

func (*ComponentObj) SubComponents

func (com *ComponentObj) SubComponents() []Component

type ContentLine

type ContentLine string

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}
Example
var r io.Reader

dec := NewDecoder(r)
for {
	c, err := dec.Decode()
	cal := NewCalendar()
	cal.SubComponentsObj = c.SubComponents()
	cal.NameObj = c.Name()
	cal.PropertiesObj = c.Properties()
	if err == io.EOF {
		break
	} else if err != nil {
		log.Fatal(err)
	}

	for _, event := range cal.GetEvents() {
		props := event.Properties()
		var summary string
		for _, p := range props {
			if p.Name == PropSummary {
				s, err := p.GetToText()
				if err != nil {
					panic(err)
				}
				summary = s
			}
		}

		log.Printf("Found event: %v", summary)
	}
}
Output:

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode() (Calendar, error)

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}
Example
event := NewEvent()
p := NewProperty(PropUID)
p.Value = ToText("uid@example.org")
event.PropertiesObj = append(event.PropertiesObj, *p)

p = NewProperty(PropDatetimeStamp)
p.SetFromDatetime(time.Now())
event.PropertiesObj = append(event.PropertiesObj, *p)
p = NewProperty(PropSummary)
p.SetFromText("Event Test")
event.PropertiesObj = append(event.PropertiesObj, *p)

p = NewProperty(PropDatetimeStart)
p.SetFromDatetime(time.Now().Add(24 * time.Hour))

cal := NewCalendar()
cal.SubComponentsObj = append(cal.SubComponentsObj, event.SubComponents()...)

var buf bytes.Buffer
if err := NewEncoder(&buf).Encode(cal); err != nil {
	log.Fatal(err)
}

log.Print(buf.String())
Output:

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (enc *Encoder) Encode(com Component) error

type ParamItem

type ParamItem interface {
	ParamItem(...interface{}) (string, []string)
}

all Parameters should implement this interface

func NewParamCN

func NewParamCN(cn string) ParamItem

func NewParamEncoding

func NewParamEncoding(enc string) ParamItem

func NewParamFMTtype

func NewParamFMTtype(formattype string) ParamItem

func NewParamItem

func NewParamItem(name string, values []string) ParamItem

func NewParamRSVP

func NewParamRSVP(rsvp bool) ParamItem

func NewParamValue

func NewParamValue(val string) ParamItem

type ParamItemObj

type ParamItemObj struct {
	Key    string
	Values []string
}

used to store ONE parameter,and implement ParamKeyValues

func (*ParamItemObj) ParamItem

func (p *ParamItemObj) ParamItem(...interface{}) (string, []string)

type Parameters

type Parameters map[string][]string

func (Parameters) Add

func (p Parameters) Add(k, v string)

one ParamItem can have multi values,add one value to an existed ParamItem

func (Parameters) AddItem

func (p Parameters) AddItem(pi ParamItem)

one ParamItem can have multi values,add one value to an existed ParamItem

func (Parameters) Del

func (p Parameters) Del(k string)

func (Parameters) DelItem

func (p Parameters) DelItem(pi ParamItem)

func (Parameters) Get

func (p Parameters) Get(name string) string

func (Parameters) GetItem

func (p Parameters) GetItem(name string) ParamItem

func (Parameters) Set

func (p Parameters) Set(k, v string)

func (Parameters) SetItem

func (p Parameters) SetItem(pi ParamItem)

type Property

type Property struct {
	Name   string
	Params Parameters
	Value  string
}

=============================Property======================================

a property is a contentline in icalendar object contentline = name *(";" param ) ":" value CRLF one name none/one/multi parameters,parameters is key-value one value

func NewProperty

func NewProperty(name string) *Property

func (*Property) GetParamValue

func (p *Property) GetParamValue() string

func (*Property) GetToBinary

func (p *Property) GetToBinary() ([]byte, error)

TODO:only base64?

func (*Property) GetToBool

func (p *Property) GetToBool() (bool, error)

func (*Property) GetToDate

func (p *Property) GetToDate() (time.Time, error)

func (*Property) GetToDatetime

func (p *Property) GetToDatetime() (time.Time, error)

func (*Property) GetToDuration

func (p *Property) GetToDuration() (time.Duration, error)

func (*Property) GetToFloat

func (p *Property) GetToFloat() (float64, error)

func (*Property) GetToInt

func (p *Property) GetToInt() (int, error)

func (*Property) GetToText

func (p *Property) GetToText() (string, error)

func (*Property) GetToTextlines

func (p *Property) GetToTextlines() ([]string, error)

func (*Property) SetFromBinary

func (p *Property) SetFromBinary(b []byte)

func (*Property) SetFromDatetime

func (p *Property) SetFromDatetime(t time.Time)

func (*Property) SetFromDuration

func (p *Property) SetFromDuration(d time.Duration)

func (*Property) SetFromText

func (p *Property) SetFromText(text string)

func (*Property) SetFromTextlines

func (p *Property) SetFromTextlines(lines []string)

func (*Property) UpdateParamValue

func (p *Property) UpdateParamValue(vdt string)

type VAlarm

type VAlarm struct {
	ComponentObj
}

type VEvent

type VEvent struct {
	ComponentObj
}

func NewEvent

func NewEvent() *VEvent

func (*VEvent) SetProperty

func (ev *VEvent) SetProperty(pname string, val string, pis ...ParamItem)

type VFreeBusy

type VFreeBusy struct {
	ComponentObj
}

type VJournal

type VJournal struct {
	ComponentObj
}

type VTZDAYLIGHT

type VTZDAYLIGHT struct {
	ComponentObj
}

type VTZSTANDARD

type VTZSTANDARD struct {
	ComponentObj
}

type VTimezone

type VTimezone struct {
	ComponentObj
}

type VTodo

type VTodo struct {
	ComponentObj
}

Jump to

Keyboard shortcuts

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