fix(static): move static files to new place for embeding
This commit is contained in:
parent
6c171eed39
commit
8162fc15f3
17 changed files with 40 additions and 328 deletions
38
static/fs.go
Normal file
38
static/fs.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package static
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed public/*
|
||||
var embedFS embed.FS
|
||||
|
||||
type EmbedStaticFS struct {
|
||||
http.FileSystem
|
||||
}
|
||||
|
||||
func NewEmbedStaticFS() (*EmbedStaticFS, error) {
|
||||
// the public folder will temporarily be copied to here in building
|
||||
publicFS, err := fs.Sub(embedFS, "public")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
httpFS := http.FS(publicFS)
|
||||
|
||||
return &EmbedStaticFS{
|
||||
FileSystem: httpFS,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (efs *EmbedStaticFS) Exists(prefix string, path string) bool {
|
||||
// prefix should already be considered by http.FileSystem
|
||||
_, err := efs.Open(path)
|
||||
if err != nil {
|
||||
// TODO: need more checking
|
||||
// if errors.Is(err, fs.ErrNotExist) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue