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 0330540f87
Use fs for language, add lang_files option
The local app translations are loaded, and then if [files]/lang_files
is provided (a directory containing custom translations), any found
inside it are loaded over top. This makes customizing much easier.
2021-02-12 14:28:09 +00:00

33 lines
641 B
Go

package main
import (
"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) {
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
}