Compare commits
2 Commits
2cea019aca
...
228fed989e
Author | SHA1 | Date | |
---|---|---|---|
|
228fed989e | ||
|
4eae59bd66 |
@ -1,19 +0,0 @@
|
|||||||
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,7 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -12,10 +16,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...")
|
||||||
|
|
||||||
@ -27,13 +29,37 @@ func FetchDiyHrt() error {
|
|||||||
return nil
|
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 {
|
func getIndex(c echo.Context) error {
|
||||||
var tpl bytes.Buffer
|
var tpl bytes.Buffer
|
||||||
rendering.IndexTemplate.Execute(&tpl, CurrentConfig.Template)
|
IndexTemplate.Execute(&tpl, CurrentConfig.Template)
|
||||||
|
|
||||||
return c.HTML(http.StatusOK, tpl.String())
|
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() {
|
func main() {
|
||||||
fmt.Println("running transfem startpage")
|
fmt.Println("running transfem startpage")
|
||||||
|
|
||||||
@ -54,8 +80,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Static("/assets", "frontend/assets")
|
|
||||||
e.Static("/scripts", "frontend/scripts")
|
// 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.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