1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-06-25 19:07:47 +02:00
jfa-go/static.go
Harvey Tindall fefe2d82a4
rebase 12/02, use go1.16rc1 in make, remove ioutil, start switching to io/fs for file i/o
ioutil's contents are now in io and os.
Eventually jfa-go's files will be embedded in the binary with go1.16's
new embed feature. Using io/fs will provide abstraction for accessing
these files, and allow for both embedded and non-embedded versions.
Also, internal paths to things like email templates, etc. will be
prefixed with "jfa-go:" to indicate to use the app's own Filesystem
instead of reading the file normally. This also allows for custom files
to continue to be used as they are currently.
2021-02-12 14:27:01 +00:00

31 lines
476 B
Go

package main
import (
"io/fs"
"net/http"
"strings"
)
type httpFS struct {
hfs http.FileSystem
fs fs.FS
}
func (f httpFS) Open(name string) (http.File, error) {
return f.hfs.Open(name)
}
func (f httpFS) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
stats, err := fs.Stat(f.fs, p)
if err != nil {
return false
}
if stats.IsDir() {
return false
}
return true
}
return false
}