mirror of
https://github.com/Bornholm/formidable.git
synced 2025-07-30 09:11:34 +02:00
feat: values updaters
This commit is contained in:
33
internal/data/updater/file/updater_handler.go
Normal file
33
internal/data/updater/file/updater_handler.go
Normal file
@ -0,0 +1,33 @@
|
||||
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{}
|
||||
}
|
Reference in New Issue
Block a user