domogeek/vendor/github.com/dolanor/caldav-go/icalendar/values/url.go

50 lines
1.1 KiB
Go
Raw Normal View History

2022-04-18 10:47:47 +00:00
package values
import (
"github.com/dolanor/caldav-go/icalendar/properties"
"github.com/dolanor/caldav-go/utils"
"net/url"
)
// a representation of duration for iCalendar
type Url struct {
u url.URL
}
// encodes the URL into iCalendar format
func (u *Url) EncodeICalValue() (string, error) {
return u.u.String(), nil
}
// encodes the url params for the iCalendar specification
func (u *Url) EncodeICalParams() (params properties.Params, err error) {
params = properties.Params{
properties.ValuePropertyName: "URI",
}
return
}
// decodes the URL from iCalendar format
func (u *Url) DecodeICalValue(value string) error {
if parsed, err := url.Parse(value); err != nil {
return utils.NewError(u.ValidateICalValue, "unable to parse url", u, err)
} else {
u.u = *parsed
return nil
}
}
// validates the URL for iCalendar format
func (u *Url) ValidateICalValue() error {
if _, err := url.Parse(u.u.String()); err != nil {
return utils.NewError(u.ValidateICalValue, "invalid URL object", u, err)
} else {
return nil
}
}
// creates a new iCalendar duration representation
func NewUrl(u url.URL) *Url {
return &Url{u: u}
}