Refactor out the use of rice in favor of embed (#2)

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: https://git.mills.io/prologic/spyda/pulls/2
This commit is contained in:
James Mills
2022-10-05 00:19:23 +00:00
parent 7001f3bf51
commit d4ab395515
13 changed files with 270 additions and 178 deletions

View File

@@ -10,11 +10,10 @@ import (
"syscall"
"time"
rice "github.com/GeertJohan/go.rice"
"git.mills.io/prologic/observe"
"github.com/NYTimes/gziphandler"
"github.com/gabstv/merger"
"github.com/justinas/nosurf"
"git.mills.io/prologic/observe"
"github.com/robfig/cron"
log "github.com/sirupsen/logrus"
"github.com/unrolled/logger"
@@ -23,6 +22,7 @@ import (
"git.mills.io/prologic/spyda/internal/auth"
"git.mills.io/prologic/spyda/internal/passwords"
"git.mills.io/prologic/spyda/internal/session"
"git.mills.io/prologic/spyda/internal/static"
)
var (
@@ -284,12 +284,12 @@ func (s *Server) initRoutes() {
s.router.ServeFiles("/img/*filepath", http.Dir("./internal/static/img"))
s.router.ServeFiles("/js/*filepath", http.Dir("./internal/static/js"))
} else {
cssBox := rice.MustFindBox("static/css").HTTPBox()
imgBox := rice.MustFindBox("static/img").HTTPBox()
jsBox := rice.MustFindBox("static/js").HTTPBox()
s.router.ServeFilesWithCacheControl("/css/:commit/*filepath", cssBox)
s.router.ServeFilesWithCacheControl("/img/:commit/*filepath", imgBox)
s.router.ServeFilesWithCacheControl("/js/:commit/*filepath", jsBox)
cssFS := static.GetSubFilesystem("css")
imgFS := static.GetSubFilesystem("img")
jsFS := static.GetSubFilesystem("js")
s.router.ServeFilesWithCacheControl("/css/:commit/*filepath", cssFS)
s.router.ServeFilesWithCacheControl("/img/:commit/*filepath", imgFS)
s.router.ServeFilesWithCacheControl("/js/:commit/*filepath", jsFS)
}
s.router.NotFound = http.HandlerFunc(s.NotFoundHandler)