package main import ( "os" "time" "github.com/studio-b12/gowebdav" ) type WebDAVStorage struct{ client *gowebdav.Client } func NewWebDAVStorage(cfg Config) *WebDAVStorage { c := gowebdav.NewClient(cfg.WebDAVURL, cfg.WebDAVUser, cfg.WebDAVPass) c.SetTimeout(10 * time.Minute) return &WebDAVStorage{client: c} } func (s *WebDAVStorage) MkdirAll(remoteDir string) error { return s.client.MkdirAll(remoteDir, 0755) } func (s *WebDAVStorage) ExistsSameSize(remotePath string, size int64) (bool, error) { fi, err := s.client.Stat(remotePath) if err != nil { return false, err } return fi.Size() == size, nil } func (s *WebDAVStorage) Upload(localPath, remotePath string) error { f, err := os.Open(localPath) if err != nil { return err } defer f.Close() return s.client.WriteStream(remotePath, f, 0644) } func (s *WebDAVStorage) Remove(remotePath string) error { return s.client.Remove(remotePath) } func (s *WebDAVStorage) Stat(remotePath string) error { _, err := s.client.Stat(remotePath) return err }