Use go:embed for statics (#92)
This commit is contained in:
parent
ddda39b22a
commit
1d769673ca
7 changed files with 13 additions and 76 deletions
http
10
http/http.go
10
http/http.go
|
@ -2,12 +2,12 @@ package http
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/anacrolix/missinggo/v2/filecache"
|
||||
"github.com/distribyted/distribyted"
|
||||
"github.com/distribyted/distribyted/config"
|
||||
"github.com/distribyted/distribyted/torrent"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/shurcooL/httpfs/html/vfstemplate"
|
||||
|
@ -19,9 +19,11 @@ func New(fc *filecache.Cache, ss *torrent.Stats, s *torrent.Service, ch *config.
|
|||
r.Use(gin.Recovery())
|
||||
r.Use(gin.ErrorLogger())
|
||||
|
||||
assets := distribyted.NewBinaryFileSystem(distribyted.HttpFS, "/assets")
|
||||
r.Use(static.Serve("/assets", assets))
|
||||
t, err := vfstemplate.ParseGlob(distribyted.HttpFS, nil, "/templates/*")
|
||||
r.GET("/assets/*filepath", func(c *gin.Context) {
|
||||
c.FileFromFS(c.Request.URL.Path, http.FS(distribyted.Assets))
|
||||
})
|
||||
|
||||
t, err := vfstemplate.ParseGlob(http.FS(distribyted.Templates), nil, "/templates/*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing html: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue