refactor asset with embed tool

This commit is contained in:
sentriz
2019-06-26 12:01:49 +01:00
parent e6c6d2406f
commit d8881bd31c
35 changed files with 11004 additions and 21662 deletions

View File

@@ -0,0 +1,39 @@
// +build !embed
package server
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/pkg/errors"
)
func (a *Assets) Find(path string) (time.Time, io.ReadSeeker, error) {
fullPath := filepath.Join(a.BasePath, path)
info, err := os.Stat(fullPath)
if err != nil {
return time.Time{}, nil, errors.Wrap(err, "statting asset")
}
file, err := os.Open(fullPath)
if err != nil {
return time.Time{}, nil, errors.Wrapf(ErrAssetNotFound, "%v", err)
}
return info.ModTime(), file, nil
}
func (a *Assets) FindBytes(path string) (time.Time, []byte, error) {
fullPath := filepath.Join(a.BasePath, path)
info, err := os.Stat(fullPath)
if err != nil {
return time.Time{}, nil, errors.Wrap(err, "statting asset")
}
file, err := ioutil.ReadFile(fullPath)
if err != nil {
return time.Time{}, nil, errors.Wrapf(ErrAssetNotFound, "%v", err)
}
return info.ModTime(), file, nil
}