Compare commits
No commits in common. "228fed989e728579cf9a77ad1fee8b1a5e714e36" and "2cea019aca6b2da5c2432ebdf9271b32cb189cfe" have entirely different histories.
228fed989e
...
2cea019aca
19
internal/rendering/template.go
Normal file
19
internal/rendering/template.go
Normal file
@ -0,0 +1,19 @@
|
||||
package rendering
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func getFileContent() string {
|
||||
content, err := os.ReadFile("frontend/index.html")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return string(content)
|
||||
}
|
||||
|
||||
var IndexTemplate = template.Must(template.New("index").Parse(getFileContent()))
|
39
main.go
39
main.go
@ -2,11 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -16,8 +12,10 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
||||
var CurrentConfig = rendering.NewConfig()
|
||||
|
||||
|
||||
func FetchDiyHrt() error {
|
||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||
|
||||
@ -29,37 +27,13 @@ func FetchDiyHrt() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//go:embed frontend/*
|
||||
var frontendFiles embed.FS
|
||||
|
||||
func getFileContent() string {
|
||||
content, err := frontendFiles.ReadFile("frontend/index.html")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return string(content)
|
||||
}
|
||||
|
||||
var IndexTemplate = template.Must(template.New("index").Parse(getFileContent()))
|
||||
|
||||
func getIndex(c echo.Context) error {
|
||||
var tpl bytes.Buffer
|
||||
IndexTemplate.Execute(&tpl, CurrentConfig.Template)
|
||||
rendering.IndexTemplate.Execute(&tpl, CurrentConfig.Template)
|
||||
|
||||
return c.HTML(http.StatusOK, tpl.String())
|
||||
}
|
||||
|
||||
func getFileSystem() http.FileSystem {
|
||||
fsys, err := fs.Sub(frontendFiles, "frontend")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return http.FS(fsys)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("running transfem startpage")
|
||||
|
||||
@ -80,11 +54,8 @@ func main() {
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
|
||||
// https://echo.labstack.com/docs/cookbook/embed-resources
|
||||
staticHandler := http.FileServer(getFileSystem())
|
||||
e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||
e.GET("/scripts/*", echo.WrapHandler(http.StripPrefix("/", staticHandler)))
|
||||
e.Static("/assets", "frontend/assets")
|
||||
e.Static("/scripts", "frontend/scripts")
|
||||
e.GET("/", getIndex)
|
||||
|
||||
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CurrentConfig.Server.Port)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user