formidable/internal/data/updater/file/updater_handler.go

34 lines
562 B
Go
Raw Permalink Normal View History

2022-05-10 22:31:17 +02:00
package file
import (
"io"
"net/url"
"os"
"path/filepath"
"github.com/pkg/errors"
)
const SchemeFile = "file"
type UpdaterHandler struct{}
func (h *UpdaterHandler) Match(url *url.URL) bool {
return url.Scheme == SchemeFile
}
func (u *UpdaterHandler) Update(url *url.URL) (io.WriteCloser, error) {
name := filepath.Join(url.Host, url.Path)
file, err := os.Create(name)
if err != nil {
return nil, errors.Wrapf(err, "could not open file '%s'", name)
}
return file, nil
}
func NewUpdaterHandler() *UpdaterHandler {
return &UpdaterHandler{}
}