包含Go API项目的所有源代码、配置文件、Docker配置、文档和前端资源 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
554 B
Go
33 lines
554 B
Go
package common
|
|
|
|
import (
|
|
"embed"
|
|
"github.com/gin-contrib/static"
|
|
"io/fs"
|
|
"net/http"
|
|
)
|
|
|
|
// Credit: https://github.com/gin-contrib/static/issues/19
|
|
|
|
type embedFileSystem struct {
|
|
http.FileSystem
|
|
}
|
|
|
|
func (e embedFileSystem) Exists(prefix string, path string) bool {
|
|
_, err := e.Open(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem {
|
|
efs, err := fs.Sub(fsEmbed, targetPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return embedFileSystem{
|
|
FileSystem: http.FS(efs),
|
|
}
|
|
}
|