webdav

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIDKey    contextKey = "user_id"
	UsernameKey  contextKey = "username"
	UserEmailKey contextKey = "user_email"
)

Variables

This section is empty.

Functions

func BasicAuthMiddleware

func BasicAuthMiddleware(userRepo repository.UserRepository, logger *zap.Logger) func(http.Handler) http.Handler

BasicAuthMiddleware provides HTTP Basic Authentication for WebDAV endpoints

func FormatHTTPDate

func FormatHTTPDate(t time.Time) string

FormatHTTPDate formats a time for HTTP headers (RFC 1123)

func FormatISO8601

func FormatISO8601(t time.Time) string

FormatISO8601 formats a time in ISO 8601 format

func GetUserID

func GetUserID(r *http.Request) (int64, bool)

GetUserID retrieves user ID from request context

func GetUserIDFromContext

func GetUserIDFromContext(ctx context.Context) (int64, bool)

GetUserIDFromContext extracts user ID from context

func GetUsernameFromContext

func GetUsernameFromContext(ctx context.Context) (string, bool)

GetUsernameFromContext extracts username from context

Types

type AddressDataRequest

type AddressDataRequest struct {
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"`
}

AddressDataRequest represents an address-data property request

type AddressDataType

type AddressDataType struct {
	ContentType string `xml:"content-type,attr"`
	Version     string `xml:"version,attr"`
}

AddressDataType represents a supported vCard format

type CalendarComponent

type CalendarComponent struct {
	Name string `xml:"name,attr"`
}

CalendarComponent represents a calendar component type

type CalendarDataRequest

type CalendarDataRequest struct {
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-data"`
}

CalendarDataRequest represents a calendar-data property request

type Config

type Config struct {
	Port         int
	ReadTimeout  int
	WriteTimeout int
}

Config contains WebDAV server configuration

type Error

type Error struct {
	XMLName xml.Name `xml:"DAV: error"`
}

Error represents a WebDAV error

type FileSystemStorage

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

FileSystemStorage implements Storage using the local filesystem

func NewFileSystemStorage

func NewFileSystemStorage(basePath string, logger *zap.Logger) *FileSystemStorage

NewFileSystemStorage creates a new filesystem-based storage

func (*FileSystemStorage) CopyResource

func (s *FileSystemStorage) CopyResource(src, dst string, overwrite bool) error

CopyResource copies a resource to a new location

func (*FileSystemStorage) CreateCollection

func (s *FileSystemStorage) CreateCollection(path string) error

CreateCollection creates a new collection (directory)

func (*FileSystemStorage) DeleteResource

func (s *FileSystemStorage) DeleteResource(path string) error

DeleteResource deletes a resource or collection

func (*FileSystemStorage) Exists

func (s *FileSystemStorage) Exists(path string) bool

Exists checks if a resource exists

func (*FileSystemStorage) GetResourceInfo

func (s *FileSystemStorage) GetResourceInfo(path string) (*ResourceInfo, error)

GetResourceInfo retrieves metadata for a resource

func (*FileSystemStorage) ListChildren

func (s *FileSystemStorage) ListChildren(path string) ([]*ResourceInfo, error)

ListChildren returns children of a collection

func (*FileSystemStorage) MoveResource

func (s *FileSystemStorage) MoveResource(src, dst string, overwrite bool) error

MoveResource moves a resource to a new location

func (*FileSystemStorage) ReadResource

func (s *FileSystemStorage) ReadResource(path string) (io.ReadCloser, error)

ReadResource reads the content of a resource

func (*FileSystemStorage) WriteResource

func (s *FileSystemStorage) WriteResource(path string, content io.Reader) error

WriteResource writes content to a resource

type Handler

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

Handler implements WebDAV HTTP methods

func NewHandler

func NewHandler(logger *zap.Logger, basePath string) *Handler

NewHandler creates a new WebDAV handler

func NewHandlerWithStorage

func NewHandlerWithStorage(logger *zap.Logger, basePath string, storage Storage) *Handler

NewHandlerWithStorage creates a new WebDAV handler with storage backend

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface

func (*Handler) SetStorage

func (h *Handler) SetStorage(storage Storage)

SetStorage sets the storage backend

type Href

type Href struct {
	Href string `xml:"href"`
}

Href represents a reference to a resource

type MultiStatus

type MultiStatus struct {
	XMLName   xml.Name   `xml:"DAV: multistatus"`
	Responses []Response `xml:"response"`
	SyncToken string     `xml:"sync-token,omitempty"`
}

MultiStatus represents a WebDAV multistatus response

type Prop

type Prop struct {
	ResourceType         *struct{} `xml:"DAV: resourcetype"`
	DisplayName          *struct{} `xml:"DAV: displayname"`
	GetContentType       *struct{} `xml:"DAV: getcontenttype"`
	GetETag              *struct{} `xml:"DAV: getetag"`
	GetLastModified      *struct{} `xml:"DAV: getlastmodified"`
	GetContentLength     *struct{} `xml:"DAV: getcontentlength"`
	CreationDate         *struct{} `xml:"DAV: creationdate"`
	CurrentUserPrincipal *struct{} `xml:"DAV: current-user-principal"`
	// CalDAV specific
	CalendarData                  *CalendarDataRequest `xml:"urn:ietf:params:xml:ns:caldav calendar-data"`
	CalendarHomeSet               *struct{}            `xml:"urn:ietf:params:xml:ns:caldav calendar-home-set"`
	CalendarDescription           *struct{}            `xml:"urn:ietf:params:xml:ns:caldav calendar-description"`
	CalendarColor                 *struct{}            `xml:"http://apple.com/ns/ical/ calendar-color"`
	CalendarOrder                 *struct{}            `xml:"http://apple.com/ns/ical/ calendar-order"`
	SupportedCalendarComponentSet *struct{}            `xml:"urn:ietf:params:xml:ns:caldav supported-calendar-component-set"`
	// CardDAV specific
	AddressData            *AddressDataRequest `xml:"urn:ietf:params:xml:ns:carddav address-data"`
	AddressbookHomeSet     *struct{}           `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
	AddressbookDescription *struct{}           `xml:"urn:ietf:params:xml:ns:carddav addressbook-description"`
	SupportedAddressData   *struct{}           `xml:"urn:ietf:params:xml:ns:carddav supported-address-data"`
}

Prop represents requested properties

type PropFind

type PropFind struct {
	XMLName  xml.Name  `xml:"DAV: propfind"`
	AllProp  *struct{} `xml:"allprop"`
	PropName *struct{} `xml:"propname"`
	Prop     *Prop     `xml:"prop"`
}

PropFind represents a PROPFIND request

type PropStat

type PropStat struct {
	Prop   PropValue `xml:"prop"`
	Status string    `xml:"status"`
}

PropStat represents property status

type PropValue

type PropValue struct {
	ResourceType         *ResourceType `xml:"DAV: resourcetype,omitempty"`
	DisplayName          *string       `xml:"DAV: displayname,omitempty"`
	GetContentType       *string       `xml:"DAV: getcontenttype,omitempty"`
	GetETag              *string       `xml:"DAV: getetag,omitempty"`
	GetLastModified      *string       `xml:"DAV: getlastmodified,omitempty"`
	GetContentLength     *int64        `xml:"DAV: getcontentlength,omitempty"`
	CreationDate         *string       `xml:"DAV: creationdate,omitempty"`
	CurrentUserPrincipal *Href         `xml:"DAV: current-user-principal,omitempty"`
	// CalDAV specific
	CalendarData                  *string                        `xml:"urn:ietf:params:xml:ns:caldav calendar-data,omitempty"`
	CalendarHomeSet               *Href                          `xml:"urn:ietf:params:xml:ns:caldav calendar-home-set,omitempty"`
	CalendarDescription           *string                        `xml:"urn:ietf:params:xml:ns:caldav calendar-description,omitempty"`
	CalendarColor                 *string                        `xml:"http://apple.com/ns/ical/ calendar-color,omitempty"`
	CalendarOrder                 *int                           `xml:"http://apple.com/ns/ical/ calendar-order,omitempty"`
	SupportedCalendarComponentSet *SupportedCalendarComponentSet `xml:"urn:ietf:params:xml:ns:caldav supported-calendar-component-set,omitempty"`
	// CardDAV specific
	AddressData            *string               `xml:"urn:ietf:params:xml:ns:carddav address-data,omitempty"`
	AddressbookHomeSet     *Href                 `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set,omitempty"`
	AddressbookDescription *string               `xml:"urn:ietf:params:xml:ns:carddav addressbook-description,omitempty"`
	SupportedAddressData   *SupportedAddressData `xml:"urn:ietf:params:xml:ns:carddav supported-address-data,omitempty"`
}

PropValue represents property values in a response

type PropertyUpdate

type PropertyUpdate struct {
	XMLName xml.Name `xml:"DAV: propertyupdate"`
	Set     []Set    `xml:"set"`
	Remove  []Remove `xml:"remove"`
}

type Remove

type Remove struct {
	XMLName xml.Name `xml:"DAV: remove"`
	Prop    Prop     `xml:"prop"`
}

type ResourceInfo

type ResourceInfo struct {
	Path         string
	Name         string
	IsCollection bool
	ContentType  string
	ContentLen   int64
	ETag         string
	ModTime      time.Time
	CreateTime   time.Time
	ResourceKind string // "collection", "calendar", "addressbook", "principal", "event", "contact", "file"
}

ResourceInfo contains metadata about a WebDAV resource

type ResourceType

type ResourceType struct {
	Collection  *struct{} `xml:"DAV: collection,omitempty"`
	Calendar    *struct{} `xml:"urn:ietf:params:xml:ns:caldav calendar,omitempty"`
	Addressbook *struct{} `xml:"urn:ietf:params:xml:ns:carddav addressbook,omitempty"`
	Principal   *struct{} `xml:"DAV: principal,omitempty"`
}

ResourceType represents the type of a WebDAV resource

type Response

type Response struct {
	Href      string     `xml:"href"`
	PropStats []PropStat `xml:"propstat"`
	Status    string     `xml:"status,omitempty"`
	Error     *Error     `xml:"error,omitempty"`
}

Response represents a single resource response

type Server

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

Server represents the WebDAV HTTP server

func NewServer

func NewServer(cfg *Config, caldavHandler, carddavHandler http.Handler, userRepo repository.UserRepository, logger *zap.Logger) *Server

NewServer creates a new WebDAV server with CalDAV and CardDAV handlers

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the WebDAV server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the WebDAV server

type Set

type Set struct {
	XMLName xml.Name `xml:"DAV: set"`
	Prop    Prop     `xml:"prop"`
}

type Storage

type Storage interface {
	// GetResourceInfo retrieves metadata for a resource
	GetResourceInfo(path string) (*ResourceInfo, error)

	// ListChildren returns children of a collection
	ListChildren(path string) ([]*ResourceInfo, error)

	// CreateCollection creates a new collection (directory)
	CreateCollection(path string) error

	// DeleteResource deletes a resource or collection
	DeleteResource(path string) error

	// CopyResource copies a resource to a new location
	CopyResource(src, dst string, overwrite bool) error

	// MoveResource moves a resource to a new location
	MoveResource(src, dst string, overwrite bool) error

	// ReadResource reads the content of a resource
	ReadResource(path string) (io.ReadCloser, error)

	// WriteResource writes content to a resource
	WriteResource(path string, content io.Reader) error

	// Exists checks if a resource exists
	Exists(path string) bool
}

Storage defines the interface for WebDAV resource storage

type SupportedAddressData

type SupportedAddressData struct {
	AddressDataTypes []AddressDataType `xml:"address-data-type"`
}

SupportedAddressData represents supported address data formats

type SupportedCalendarComponentSet

type SupportedCalendarComponentSet struct {
	Components []CalendarComponent `xml:"comp"`
}

SupportedCalendarComponentSet represents supported calendar component types

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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