From 4a0c1191403809a3ec73c54c06f92d0eb5484a21 Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Thu, 30 Oct 2025 12:17:51 +0800 Subject: [PATCH 1/2] fix(web): index page does not have analytic --- common/embed-file-system.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/embed-file-system.go b/common/embed-file-system.go index d7bd2d5bd..ced636c38 100644 --- a/common/embed-file-system.go +++ b/common/embed-file-system.go @@ -4,6 +4,7 @@ import ( "embed" "io/fs" "net/http" + "os" "github.com/gin-contrib/static" ) @@ -14,7 +15,7 @@ type embedFileSystem struct { http.FileSystem } -func (e embedFileSystem) Exists(prefix string, path string) bool { +func (e *embedFileSystem) Exists(prefix string, path string) bool { _, err := e.Open(path) if err != nil { return false @@ -22,12 +23,21 @@ func (e embedFileSystem) Exists(prefix string, path string) bool { return true } +func (e *embedFileSystem) Open(name string) (http.File, error) { + if name == "/" { + // This will make sure the index page gose to NoRouter handler, + // which will use the replaced index bytes with analytic codes. + return nil, os.ErrNotExist + } + return e.FileSystem.Open(name) +} + func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem { efs, err := fs.Sub(fsEmbed, targetPath) if err != nil { panic(err) } - return embedFileSystem{ + return &embedFileSystem{ FileSystem: http.FS(efs), } } From 2a62aea46c6cd86bb1da8c9f874fe49ea9d46fe3 Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Thu, 30 Oct 2025 14:21:46 +0800 Subject: [PATCH 2/2] fix: typo --- common/embed-file-system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/embed-file-system.go b/common/embed-file-system.go index ced636c38..8de869950 100644 --- a/common/embed-file-system.go +++ b/common/embed-file-system.go @@ -25,7 +25,7 @@ func (e *embedFileSystem) Exists(prefix string, path string) bool { func (e *embedFileSystem) Open(name string) (http.File, error) { if name == "/" { - // This will make sure the index page gose to NoRouter handler, + // This will make sure the index page goes to NoRouter handler, // which will use the replaced index bytes with analytic codes. return nil, os.ErrNotExist }