Core

/assets/embed.go (435 B)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package assets

import (
"embed"
"mime"
"path/filepath"

"github.com/pkg/errors"
)

//go:embed *
var FS embed.FS

func EmbedAsset(path string) ([]byte, string, error) {
if path == "embed.go" {
return nil, "", errors.New("invalid asset")
}
data, err := FS.ReadFile(path)
if err != nil {
return nil, "", errors.Wrapf(err, "error reading asset at [%s]", path)
}

return data, mime.TypeByExtension(filepath.Ext(path)), nil
}