data

package
v0.0.0-...-0190efd Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TAG_FILTER         = "filter"
	TAG_COMP_FILTER    = "comp-filter"
	TAG_PROP_FILTER    = "prop-filter"
	TAG_PARAM_FILTER   = "param-filter"
	TAG_TIME_RANGE     = "time-range"
	TAG_TEXT_MATCH     = "text-match"
	TAG_IS_NOT_DEFINED = "is-not-defined"

	// From the RFC, the time range `start` and `end` attributes MUST be in UTC and in this specific format
	FILTER_TIME_FORMAT = "20060102T150405Z"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CalUser

type CalUser struct {
	Name string
}

CalUser represents the calendar user. It is used, for example, to keep track globally what is the current user interacting with the calendar. This user data can be used in various places, including in some of the CALDAV responses.

type FileResourceAdapter

type FileResourceAdapter struct {
	// contains filtered or unexported fields
}

FileResourceAdapter implements the `ResourceAdapter` for resources stored as files in the file system.

func (*FileResourceAdapter) CalculateEtag

func (adp *FileResourceAdapter) CalculateEtag() string

CalculateEtag calculates an ETag based on the file current modification status and returns it.

func (*FileResourceAdapter) GetContent

func (adp *FileResourceAdapter) GetContent() string

GetContent reads the file content and returns it as string. For collection resources (directories), it returns an empty string.

func (*FileResourceAdapter) GetContentSize

func (adp *FileResourceAdapter) GetContentSize() int64

GetContentSize returns the content length.

func (*FileResourceAdapter) GetModTime

func (adp *FileResourceAdapter) GetModTime() time.Time

GetModTime returns the time when the file was last modified.

func (*FileResourceAdapter) IsCollection

func (adp *FileResourceAdapter) IsCollection() bool

IsCollection tells whether the file resource is a directory or not.

type FileStorage

type FileStorage struct{}

FileStorage is the storage that deals with resources as files in the file system. So, a collection resource is treated as a folder/directory and its children resources are the files it contains. Non-collection resources are just plain files. Each file represents then a CalAV resource and the data expects to contain the iCal data to feed the calendar events.

func (*FileStorage) CreateResource

func (fs *FileStorage) CreateResource(rpath, content string) (*Resource, error)

CreateResource creates a file resource with the provided `content`. See `Storage.CreateResource` doc.

func (*FileStorage) DeleteResource

func (fs *FileStorage) DeleteResource(rpath string) error

DeleteResource deletes a file resource (and possibly all its children in case of a collection). See `Storage.DeleteResource` doc.

func (*FileStorage) GetResource

func (fs *FileStorage) GetResource(rpath string) (*Resource, bool, error)

GetResource fetches and returns a single resource for a `rpath`. See `Storage.GetResoure` doc.

func (*FileStorage) GetResources

func (fs *FileStorage) GetResources(rpath string, withChildren bool) ([]Resource, error)

GetResources get the file resources based on the `rpath`. See `Storage.GetResources` doc.

func (*FileStorage) GetResourcesByFilters

func (fs *FileStorage) GetResourcesByFilters(rpath string, filters *ResourceFilter) ([]Resource, error)

GetResourcesByFilters get the file resources based on the `rpath` and a set of filters. See `Storage.GetResourcesByFilters` doc.

func (*FileStorage) GetResourcesByList

func (fs *FileStorage) GetResourcesByList(rpaths []string) ([]Resource, error)

GetResourcesByList get a list of file resources based on a list of `rpaths`. See `Storage.GetResourcesByList` doc.

func (*FileStorage) GetShallowResource

func (fs *FileStorage) GetShallowResource(rpath string) (*Resource, bool, error)

GetShallowResource fetches and returns a single resource file/directory without any related children. See `Storage.GetShallowResource` doc.

func (*FileStorage) UpdateResource

func (fs *FileStorage) UpdateResource(rpath, content string) (*Resource, error)

UpdateResource updates a file resource with the provided `content`. See `Storage.UpdateResource` doc.

type Resource

type Resource struct {
	Name string
	Path string
	// contains filtered or unexported fields
}

Resource represents the CalDAV resource. Basically, it has a name it's accessible based on path. A resource can be a collection, meaning it doesn't have any data content, but it has child resources. A non-collection is the actual resource which has the data in iCal format and which will feed the calendar. When visualizing the whole resources set in a tree representation, the collection resource would be the inner nodes and the non-collection would be the leaves.

func NewResource

func NewResource(rawPath string, adp ResourceAdapter) Resource

NewResource initializes a new `Resource` instance based on its path and the `ResourceAdapter` implementation to be used.

func (*Resource) ComponentName

func (r *Resource) ComponentName() string

ComponentName returns the type of the resource. VCALENDAR for collection resources, VEVENT otherwise.

func (*Resource) EndTimeUTC

func (r *Resource) EndTimeUTC() time.Time

EndTimeUTC returns the end time in UTC of a VEVENT resource.

func (*Resource) GetContentData

func (r *Resource) GetContentData() (string, bool)

GetContentData reads and returns the raw content of the resource as string and flag saying if the content was found. If the resource does not have content (like collection resource), it returns an empty string and false.

func (*Resource) GetContentLength

func (r *Resource) GetContentLength() (string, bool)

GetContentLength returns the length of the resource's content and flag saying if the length is present. If the resource does not have content (like collection resource), it returns an empty string and false.

func (*Resource) GetContentType

func (r *Resource) GetContentType() (string, bool)

GetContentType returns the type of the content of the resource. Collection resources are "text/calendar". Non-collection resources are "text/calendar; component=vcalendar".

func (*Resource) GetDisplayName

func (r *Resource) GetDisplayName() (string, bool)

GetDisplayName returns the name/identifier of the resource.

func (*Resource) GetEtag

func (r *Resource) GetEtag() (string, bool)

GetEtag returns the ETag of the resource and a flag saying if the ETag is present. For collection resource, it returns an empty string and false.

func (*Resource) GetLastModified

func (r *Resource) GetLastModified(format string) (string, bool)

GetLastModified returns the last time the resource was modified. The returned time is returned formatted in the provided `format`.

func (*Resource) GetOwner

func (r *Resource) GetOwner() (string, bool)

GetOwner returns the owner of the resource. This is usually the principal resource associated (the root resource). If the resource does not have a owner (for example it's a principal resource alread), it returns an empty string.

func (*Resource) GetOwnerPath

func (r *Resource) GetOwnerPath() (string, bool)

GetOwnerPath returns the path to this resource's owner, or an empty string when the resource does not have any owner.

func (*Resource) GetPropertyParamValue

func (r *Resource) GetPropertyParamValue(paramPath ...string) string

GetPropertyParamValue gets a property param value from the resource's iCal content. The path to the param should be provided in case of nested params. Example, suppose the resource has this content:

BEGIN:VCALENDAR
BEGIN:VEVENT
ATTENDEE;PARTSTAT=NEEDS-ACTION:FOO
END:VEVENT
END:VCALENDAR

GetPropertyParamValue("VEVENT", "ATTENDEE", "PARTSTAT") => returns "NEEDS-ACTION" GetPropertyParamValue("VEVENT", "ATTENDEE", "OTHER") => returns ""

func (*Resource) GetPropertyValue

func (r *Resource) GetPropertyValue(propPath ...string) string

GetPropertyValue gets a property value from the resource's iCal content. The path to the property should be provided in case of nested properties. Example, suppose the resource has this content:

BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20160914T170000
END:VEVENT
END:VCALENDAR

GetPropertyValue("VEVENT", "DTSTART") => returns "20160914T170000" GetPropertyValue("VEVENT", "DTEND") => returns ""

func (*Resource) HasProperty

func (r *Resource) HasProperty(propPath ...string) bool

HasProperty tells whether the resource has the provided property in its iCal content. The path to the property should be provided in case of nested properties. Example, suppose the resource has this content:

BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20160914T170000
END:VEVENT
END:VCALENDAR

HasProperty("VEVENT", "DTSTART") => returns true HasProperty("VEVENT", "DTEND") => returns false

func (*Resource) HasPropertyParam

func (r *Resource) HasPropertyParam(paramPath ...string) bool

HasPropertyParam tells whether the resource has the provided property param in its iCal content. The path to the param should be provided in case of nested params. Example, suppose the resource has this content:

BEGIN:VCALENDAR
BEGIN:VEVENT
ATTENDEE;PARTSTAT=NEEDS-ACTION:FOO
END:VEVENT
END:VCALENDAR

HasPropertyParam("VEVENT", "ATTENDEE", "PARTSTAT") => returns true HasPropertyParam("VEVENT", "ATTENDEE", "OTHER") => returns false

func (*Resource) IsCollection

func (r *Resource) IsCollection() bool

IsCollection tells whether a resource is a collection or not.

func (*Resource) IsPrincipal

func (r *Resource) IsPrincipal() bool

IsPrincipal tells whether a resource is the principal resource or not. A principal resource means it's a root resource.

func (*Resource) Recurrences

func (r *Resource) Recurrences() []ResourceRecurrence

Recurrences returns an array of resource recurrences. NOTE: Recurrences are not supported yet. An empty array will always be returned.

func (*Resource) StartTimeUTC

func (r *Resource) StartTimeUTC() time.Time

StartTimeUTC returns the start time in UTC of a VEVENT resource.

type ResourceAdapter

type ResourceAdapter interface {
	IsCollection() bool
	CalculateEtag() string
	GetContent() string
	GetContentSize() int64
	GetModTime() time.Time
}

ResourceAdapter serves as the object to abstract all the specicities in different resources implementations. For example, the way to tell whether a resource is a collection or how to read its content differentiates on resources stored in the file system, coming from a relational DB or from the cloud as JSON. These differentiations should be covered by providing a specific implementation of the `ResourceAdapter` interface. So, depending on the current resource storage strategy, a matching resource adapter implementation should be provided whenever a new resource is initialized.

type ResourceFilter

type ResourceFilter struct {
	// contains filtered or unexported fields
}

ResourceFilter represents filters to filter out resources. Filters are basically a set of rules used to retrieve a range of resources. It is used primarily on REPORT requests and is described in details in RFC4791#7.8.

func ParseResourceFilters

func ParseResourceFilters(xml string) (*ResourceFilter, error)

ParseResourceFilters initializes a new `ResourceFilter` object from a snippet of XML string.

func (*ResourceFilter) Attr

func (f *ResourceFilter) Attr(attrName string) string

Attr searches an attribute by its name in the list of filter attributes and returns it.

func (*ResourceFilter) GetTimeRangeFilter

func (f *ResourceFilter) GetTimeRangeFilter() *ResourceFilter

GetTimeRangeFilter checks if the current filter has a child "time-range" filter and returns it (wrapped in a `ResourceFilter` type). It returns nil if the current filter does not contain any "time-range" filter.

func (*ResourceFilter) Match

func (f *ResourceFilter) Match(target ResourceInterface) bool

Match returns whether a provided resource matches the filters.

func (*ResourceFilter) TimeAttr

func (f *ResourceFilter) TimeAttr(attrName string) *time.Time

TimeAttr searches and returns a filter attribute as a `time.Time` object.

type ResourceInterface

type ResourceInterface interface {
	ComponentName() string
	StartTimeUTC() time.Time
	EndTimeUTC() time.Time
	Recurrences() []ResourceRecurrence
	HasProperty(propPath ...string) bool
	GetPropertyValue(propPath ...string) string
	HasPropertyParam(paramName ...string) bool
	GetPropertyParamValue(paramName ...string) string
}

ResourceInterface defines the main interface of a CalDAV resource object. This interface exists only to define the common resource operation and should not be custom-implemented. The default and canonical implementation is provided by `data.Resource`, convering all the commonalities. Any specifics in implementations should be handled by the `data.ResourceAdapter`.

type ResourceRecurrence

type ResourceRecurrence struct {
	StartTime time.Time
	EndTime   time.Time
}

ResourceRecurrence represents a recurrence for a resource. NOTE: recurrences are not supported yet.

type Storage

type Storage interface {
	// GetResources gets a list of resources based on a given `rpath`. The
	// `rpath` is the path to the original resource that's being requested. The resultant list
	// will/must contain that original resource in it, apart from any additional resources. It also receives
	// `withChildren` flag to say if the result must also include all the original resource`s
	// children (if original is a collection resource). If `true`, the result will have the requested resource + children.
	// If `false`, it will have only the requested original resource (from the `rpath` path).
	// It returns errors if anything went wrong or if it could not find any resource on `rpath` path.
	GetResources(rpath string, withChildren bool) ([]Resource, error)
	// GetResourcesByList fetches a list of resources by path from the storage.
	// This method fetches all the `rpaths` and return an array of the reosurces found.
	// No error 404 will be returned if one of the resources cannot be found.
	// Errors are returned if any errors other than "not found" happens.
	GetResourcesByList(rpaths []string) ([]Resource, error)
	// GetResourcesByFilters returns the filtered children of a target collection resource.
	// The target collection resource is the one pointed by the `rpath` parameter. All of its children
	// will be checked against a set of `filters` and the matching ones are returned. The results
	// contains only the filtered children and does NOT include the target resource. If the target resource
	// is not a collection, an empty array is returned as the result.
	GetResourcesByFilters(rpath string, filters *ResourceFilter) ([]Resource, error)
	// GetResource gets the requested resource based on a given `rpath` path. It returns the resource (if found) or
	// nil (if not found). Also returns a flag specifying if the resource was found or not.
	GetResource(rpath string) (*Resource, bool, error)
	// GetShallowResource has the same behaviour of `storage.GetResource`. The only difference is that, for collection resources,
	// it does not return its children in the collection `storage.Resource` struct (hence the name shallow). The motive is
	// for optimizations reasons, as this function is used on places where the collection's children are not important.
	GetShallowResource(rpath string) (*Resource, bool, error)
	// CreateResource creates a new resource on the `rpath` path with a given `content`.
	CreateResource(rpath, content string) (*Resource, error)
	// UpdateResource udpates a resource on the `rpath` path with a given `content`.
	UpdateResource(rpath, content string) (*Resource, error)
	// DeleteResource deletes a resource on the `rpath` path.
	DeleteResource(rpath string) error
}

Storage is the inteface responsible for the CRUD operations on the CalDAV resources. It represents where the resources should be fetched from and the various operations which can be performed on it. This is the interface one should implement in case it needs a custom storage strategy, like fetching data from the cloud, local DB, etc. After that, the custom storage implementation can be setup to be used in the server by passing the object instance to `caldav.SetupStorage`.

Jump to

Keyboard shortcuts

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