using embeded file system for static files
This commit is contained in:
parent
2cea019aca
commit
4eae59bd66
23
main.go
23
main.go
@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -12,10 +14,8 @@ import (
|
|||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var CurrentConfig = rendering.NewConfig()
|
var CurrentConfig = rendering.NewConfig()
|
||||||
|
|
||||||
|
|
||||||
func FetchDiyHrt() error {
|
func FetchDiyHrt() error {
|
||||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||||
|
|
||||||
@ -34,6 +34,18 @@ func getIndex(c echo.Context) error {
|
|||||||
return c.HTML(http.StatusOK, tpl.String())
|
return c.HTML(http.StatusOK, tpl.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed frontend/*
|
||||||
|
var frontendFiles embed.FS
|
||||||
|
|
||||||
|
func getFileSystem() http.FileSystem {
|
||||||
|
fsys, err := fs.Sub(frontendFiles, "frontend")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.FS(fsys)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("running transfem startpage")
|
fmt.Println("running transfem startpage")
|
||||||
|
|
||||||
@ -54,8 +66,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Static("/assets", "frontend/assets")
|
// "frontend/assets"
|
||||||
e.Static("/scripts", "frontend/scripts")
|
|
||||||
|
staticHandler := http.FileServer(getFileSystem())
|
||||||
|
e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||||
|
e.GET("/scripts/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||||
e.GET("/", getIndex)
|
e.GET("/", getIndex)
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
|
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user