summaryrefslogtreecommitdiff
path: root/src/post/asset/loader.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/post/asset/loader.go')
-rw-r--r--src/post/asset/loader.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/post/asset/loader.go b/src/post/asset/loader.go
new file mode 100644
index 0000000..f7a0f5e
--- /dev/null
+++ b/src/post/asset/loader.go
@@ -0,0 +1,43 @@
+package asset
+
+import (
+ "errors"
+ "io"
+ "path/filepath"
+)
+
+var (
+ ErrCannotResize = errors.New("cannot resize")
+)
+
+// LoadOpts are optional parameters to Loader's Load method. Some may only apply
+// to specific Loader implementations.
+type LoadOpts struct {
+
+ // ImageWidth is used by the ImageLoader to resize images on the fly.
+ ImageWidth int
+}
+
+// Loader is used to load an asset and write its body into the given io.Writer.
+//
+// Errors:
+// - ErrNotFound
+// - ErrCannotResize (only if ImageLoader is used)
+type Loader interface {
+ Load(path string, into io.Writer, opts LoadOpts) error
+}
+
+type storeLoader struct {
+ store Store
+}
+
+// NewStoreLoader returns a Loader which loads assets directly from the given
+// Store, with no transformation.
+func NewStoreLoader(store Store) Loader {
+ return &storeLoader{store}
+}
+
+func (l *storeLoader) Load(path string, into io.Writer, opts LoadOpts) error {
+ id := filepath.Base(path)
+ return l.store.Get(id, into)
+}