wp-go/internal/static/static.go

29 lines
524 B
Go
Raw Permalink Normal View History

2022-09-13 03:23:28 +00:00
package static
import (
"embed"
"errors"
"io/fs"
"path/filepath"
"strings"
)
2022-09-22 13:59:33 +00:00
//go:embed wp-content wp-includes favicon.ico
2023-01-30 12:16:03 +00:00
var FsDir embed.FS
2022-09-13 03:23:28 +00:00
type Fs struct {
embed.FS
Path string
}
func (f Fs) Open(path string) (fs.File, error) {
if filepath.Separator != '/' && strings.ContainsRune(path, filepath.Separator) {
return nil, errors.New("http: invalid character in file path")
}
fullName := strings.TrimLeft(path, "/")
fullName = f.Path + "/" + fullName
file, err := f.FS.Open(fullName)
return file, err
}