Init
This commit is contained in:
commit
f90fdc0598
99 changed files with 15260 additions and 0 deletions
26
api/static.go
Normal file
26
api/static.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue