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

34 lines
562 B
Go

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{}
}