Skip to content

Commit 2391fa0

Browse files
authored
Merge pull request #523 from linthan/adjustwindow
feat: 兼容window文件查找
2 parents 660240f + eeb322d commit 2391fa0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

api/apiv1/static/filesystem.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func (d Dir) Exists(name string) bool {
2828
}
2929
fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
3030
fullName = strings.TrimPrefix(fullName, strings.TrimPrefix(Prefix, "/"))
31+
fullName = strings.TrimPrefix(fullName, string(filepath.Separator))
32+
fullName = strings.ReplaceAll(fullName, "\\", "/")
3133
_, err := statikFS.Open(fullName)
3234
return err == nil
3335
}
@@ -38,7 +40,10 @@ func (d Dir) Open(name string) (http.File, error) {
3840
if dir == "" {
3941
dir = "."
4042
}
43+
4144
fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
4245
fullName = strings.TrimPrefix(fullName, strings.TrimPrefix(Prefix, "/"))
46+
fullName = strings.TrimPrefix(fullName, string(filepath.Separator))
47+
fullName = strings.ReplaceAll(fullName, "\\", "/")
4348
return statikFS.Open(fullName)
4449
}

assets/assets.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ package assets
55

66
import (
77
"net/http"
8+
"path/filepath"
89
)
910

1011
var AssetsEmbedded = false
1112

1213
func Assets() (http.FileSystem, error) {
13-
return http.Dir("./assets/dist"), nil
14+
pathDir := filepath.Join(".", "assets", "dist")
15+
return http.Dir(pathDir), nil
1416
}

0 commit comments

Comments
 (0)