blob: f7a0f5e9db8ffa7ce6794fca3dd03d61849abe82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}
|