feat: add null:// update handler

This commit is contained in:
wpetit 2022-08-01 15:33:41 +02:00 committed by Bornholm
parent ab4f498b7c
commit bbdfb30205
3 changed files with 40 additions and 0 deletions

View File

@ -87,6 +87,10 @@ echo '{}' | FORMIDABLE_BROWSER="firefox" frmd \
> TODO: Write doc + example
#### `null://`
> TODO: Write doc + example
#### `file://`
> TODO: Write doc + example

View File

@ -16,6 +16,7 @@ import (
"forge.cadoles.com/wpetit/formidable/internal/data/scheme/stdin"
"forge.cadoles.com/wpetit/formidable/internal/data/updater/exec"
fileUpdater "forge.cadoles.com/wpetit/formidable/internal/data/updater/file"
"forge.cadoles.com/wpetit/formidable/internal/data/updater/null"
"forge.cadoles.com/wpetit/formidable/internal/data/updater/stdout"
"forge.cadoles.com/wpetit/formidable/internal/def"
"github.com/pkg/errors"
@ -205,6 +206,7 @@ func newUpdater() *data.Updater {
stdout.NewUpdaterHandler(),
fileUpdater.NewUpdaterHandler(),
exec.NewUpdaterHandler(),
null.NewUpdaterHandler(),
)
}

View File

@ -0,0 +1,34 @@
package null
import (
"io"
"net/url"
)
const SchemeNull = "null"
type UpdaterHandler struct{}
func (h *UpdaterHandler) Match(url *url.URL) bool {
return url.Scheme == SchemeNull
}
func (u *UpdaterHandler) Update(url *url.URL) (io.WriteCloser, error) {
return &nullCloser{}, nil
}
func NewUpdaterHandler() *UpdaterHandler {
return &UpdaterHandler{}
}
type nullCloser struct {
io.WriteCloser
}
func (c *nullCloser) Write(p []byte) (n int, err error) {
return io.Discard.Write(p)
}
func (c *nullCloser) Close() error {
return nil
}