mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-10-18 09:00:11 +00:00
Harvey Tindall
e1af1eeab5
paths are pretty janky, but it works. Also, [files]/lang_files now must be the path to a directory CONTAINING a "lang/" directory. I'll work around this at a later date.
35 lines
723 B
Go
35 lines
723 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Since the gin-static middleware uses a version of http.Filesystem with an extra Exists() func, we extend it here.
|
|
|
|
type httpFS struct {
|
|
hfs http.FileSystem // Created by converting fs.FS using http.FS()
|
|
fs fs.FS
|
|
}
|
|
|
|
func (f httpFS) Open(name string) (http.File, error) {
|
|
fmt.Println("build/data/web" + name)
|
|
return f.hfs.Open("build/data/web" + 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, "build/data/web/"+p)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
if stats.IsDir() {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|