Use go:embed for statics ()

This commit is contained in:
Antonio Navarro Perez 2021-11-21 18:31:47 +01:00 committed by GitHub
parent ddda39b22a
commit 1d769673ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 76 deletions

View file

@ -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)
}