mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
add support for the go standard embed tag for locale files
This commit is contained in:
@@ -372,7 +372,7 @@ func FileServer(fs http.FileSystem, options DirOptions) context.Handler {
|
||||
}
|
||||
|
||||
prefixURL := strings.TrimSuffix(r.RequestURI, name)
|
||||
names, err := findNames(fs, name)
|
||||
names, err := context.FindNames(fs, name)
|
||||
if err == nil {
|
||||
for _, indexAsset := range names {
|
||||
// it's an index file, do not pushed that.
|
||||
@@ -858,7 +858,7 @@ func fsOpener(fs http.FileSystem, options DirCacheOptions) func(name string, r *
|
||||
func cache(fs http.FileSystem, options DirCacheOptions) (*cacheFS, error) {
|
||||
start := time.Now()
|
||||
|
||||
names, err := findNames(fs, "/")
|
||||
names, err := context.FindNames(fs, "/")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1175,49 +1175,6 @@ func (f *file) Get(alg string) (http.File, error) {
|
||||
return f.Get("")
|
||||
}
|
||||
|
||||
func findNames(fs http.FileSystem, name string) ([]string, error) {
|
||||
f, err := fs.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
return []string{name}, nil
|
||||
}
|
||||
|
||||
fileinfos, err := f.Readdir(-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files := make([]string, 0)
|
||||
|
||||
for _, info := range fileinfos {
|
||||
// Note:
|
||||
// go-bindata has absolute names with os.Separator,
|
||||
// http.Dir the basename.
|
||||
filename := toBaseName(info.Name())
|
||||
fullname := path.Join(name, filename)
|
||||
if fullname == name { // prevent looping through itself when fs is cacheFS.
|
||||
continue
|
||||
}
|
||||
rfiles, err := findNames(fs, fullname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files = append(files, rfiles...)
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
||||
|
||||
type fileInfo struct {
|
||||
baseName string
|
||||
modTime time.Time
|
||||
|
||||
Reference in New Issue
Block a user