loading diyhrt data in template
This commit is contained in:
parent
1892da9682
commit
51ec608e65
@ -1,6 +1,8 @@
|
||||
package rendering
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||
)
|
||||
|
||||
type RenderingConfig struct {
|
||||
HeaderPhrases []string
|
||||
@ -10,6 +12,9 @@ type RenderingConfig struct {
|
||||
SearchPlaceholder string
|
||||
SearchFormAction string
|
||||
SearchInputName string
|
||||
|
||||
Listings []diyhrt.Listing
|
||||
Stores []diyhrt.Store
|
||||
}
|
||||
|
||||
func DefaultRenderingConfig() RenderingConfig {
|
||||
@ -32,11 +37,18 @@ func DefaultRenderingConfig() RenderingConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RenderingConfig) Set(key string, value string) {
|
||||
// https://gist.github.com/kilfu0701/77c614386483782f68bc5538b6100730
|
||||
r := reflect.ValueOf(rc)
|
||||
f := reflect.Indirect(r).FieldByName(key)
|
||||
if f.Kind() != reflect.Invalid {
|
||||
f.SetString(value)
|
||||
func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||
existingStores := make(map[int]struct{})
|
||||
stores := make([]diyhrt.Store, 0)
|
||||
|
||||
for _, listing := range listings {
|
||||
if _, ok := existingStores[listing.Store.Id]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
stores = append(stores, listing.Store)
|
||||
}
|
||||
|
||||
rc.Listings = listings
|
||||
rc.Stores = stores
|
||||
}
|
||||
|
13
main.go
13
main.go
@ -5,12 +5,24 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/rendering"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var CurrentRenderingConfig = rendering.DefaultRenderingConfig()
|
||||
|
||||
func FetchDiyHrt() error {
|
||||
fmt.Println("Fetch DiyHrt Marketplaces...")
|
||||
|
||||
l, err := diyhrt.GetListings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
CurrentRenderingConfig.LoadDiyHrt(l)
|
||||
return nil
|
||||
}
|
||||
|
||||
func setConfig(c echo.Context) error {
|
||||
err := c.Bind(&CurrentRenderingConfig)
|
||||
if err != nil {
|
||||
@ -29,6 +41,7 @@ func getIndex(c echo.Context) error {
|
||||
|
||||
func main() {
|
||||
fmt.Println("running transfem startpage")
|
||||
FetchDiyHrt()
|
||||
|
||||
e := echo.New()
|
||||
e.Static("/assets", "frontend/assets")
|
||||
|
Loading…
x
Reference in New Issue
Block a user