mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-10-18 09:00:11 +00:00
Harvey Tindall
88c7d8e606
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.
31 lines
476 B
Go
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
|
|
}
|