ics - encoder.go
1 package ics
2
3 import (
4 "errors"
5 "io"
6 )
7
8 type writer interface {
9 io.Writer
10 WriteString(string) (int, error)
11 }
12
13 // Encode encodes the given iCalendar object into the writer. It first
14 // validates the iCalendar object so as not to write invalid data to the writer
15 func Encode(w io.Writer, cal *Calendar) error {
16 if err := cal.valid(); err != nil {
17 return err
18 }
19 f := folder{w: w}
20 cal.encode(&f)
21 return f.err
22 }
23
24 // Errors
25 var (
26 ErrInvalidCalendar = errors.New("invalid calendar")
27 )