26 lines
689 B
Go
26 lines
689 B
Go
package api
|
|
|
|
import (
|
|
"cafe/config"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/gin-contrib/static"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (a *Api) HandleStaticFiles() {
|
|
a.Router.LoadHTMLFiles(config.TemplatesDir + "index.html")
|
|
a.serveFoldersInTemplates()
|
|
}
|
|
|
|
func (a *Api) serveFoldersInTemplates() {
|
|
_ = filepath.WalkDir(config.TemplatesDir, func(path string, info os.DirEntry, err error) error {
|
|
if info.IsDir() && info.Name() != strings.TrimSuffix(config.TemplatesDir, "/") {
|
|
a.Router.Use(static.Serve("/"+info.Name(), static.LocalFile(config.TemplatesDir+info.Name(), false)))
|
|
logrus.WithField("folder", info.Name()).Debug("Serve static folder")
|
|
}
|
|
return err
|
|
})
|
|
}
|