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