Files

33 lines
1018 B
Go

package backup
import (
"context"
"net/http"
)
// ObjectStore is the conditional object boundary used by synchronization.
// An empty ETag creates an absent object; a nonempty ETag replaces that version.
type ObjectStore interface {
Get(context.Context, string) ([]byte, string, error)
Put(context.Context, string, []byte, string) error
}
type webDAVObjectStore struct {
config WebDAVConfig
}
// NewWebDAVObjectStore binds one operation's configuration. Validation remains
// at each exchange, alongside path, ETag, size and redirect protections.
func NewWebDAVObjectStore(config WebDAVConfig) ObjectStore {
return webDAVObjectStore{config: config}
}
func (s webDAVObjectStore) Get(ctx context.Context, key string) ([]byte, string, error) {
return WebDAVExchange(ctx, s.config, http.MethodGet, key, nil, "")
}
func (s webDAVObjectStore) Put(ctx context.Context, key string, payload []byte, etag string) error {
_, _, err := WebDAVExchange(ctx, s.config, http.MethodPut, key, payload, etag)
return err
}