lets-go:13.1 embed static

This commit is contained in:
tamsin johnson 2024-02-08 10:11:53 -08:00
parent ba6bf1a682
commit ba4f38b425
2 changed files with 12 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import (
"github.com/julienschmidt/httprouter"
"github.com/justinas/alice"
"snippetbox.chaosfem.tw/ui"
)
// routes ...
@ -20,8 +22,8 @@ func (app *application) routes() http.Handler {
})
// setup server for static files
fileServer := http.FileServer(http.Dir("./ui/static"))
router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))
fileServer := http.FileServer(http.FS(ui.Files))
router.Handler(http.MethodGet, "/static/*filepath", fileServer)
dynamic := alice.New(app.sessionManager.LoadAndSave, noSurf, app.authenticate)

8
snippetbox/ui/efs.go Normal file
View File

@ -0,0 +1,8 @@
package ui
import (
"embed"
)
//go:embed "static"
var Files embed.FS