refactored diy hrt in proper struct
This commit is contained in:
parent
231ceea80a
commit
1e7bbc6e16
7
internal/diyhrt/diy_config.go
Normal file
7
internal/diyhrt/diy_config.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package diyhrt
|
||||||
|
|
||||||
|
type DiyHrtConfig struct {
|
||||||
|
ApiKey string
|
||||||
|
StoreFilter StoreFilter
|
||||||
|
ListingFilter ListingFilter
|
||||||
|
}
|
@ -34,9 +34,6 @@ type TemplateConfig struct {
|
|||||||
SearchFormAction string
|
SearchFormAction string
|
||||||
SearchInputName string
|
SearchInputName string
|
||||||
|
|
||||||
StoreFilter diyhrt.StoreFilter
|
|
||||||
ListingFilter diyhrt.ListingFilter
|
|
||||||
|
|
||||||
Listings []diyhrt.Listing
|
Listings []diyhrt.Listing
|
||||||
Stores []diyhrt.Store
|
Stores []diyhrt.Store
|
||||||
|
|
||||||
@ -48,6 +45,7 @@ type TemplateConfig struct {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Server ServerConfig
|
Server ServerConfig
|
||||||
Template TemplateConfig
|
Template TemplateConfig
|
||||||
|
DiyHrt diyhrt.DiyHrtConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() Config {
|
func NewConfig() Config {
|
||||||
@ -55,6 +53,16 @@ func NewConfig() Config {
|
|||||||
Server: ServerConfig{
|
Server: ServerConfig{
|
||||||
Port: 5500,
|
Port: 5500,
|
||||||
},
|
},
|
||||||
|
DiyHrt: diyhrt.DiyHrtConfig{
|
||||||
|
ApiKey: os.Getenv("API_KEY"),
|
||||||
|
StoreFilter: diyhrt.StoreFilter{
|
||||||
|
Limit: 0,
|
||||||
|
IncludeIds: []int{7},
|
||||||
|
},
|
||||||
|
ListingFilter: diyhrt.ListingFilter{
|
||||||
|
FromStores: []int{7},
|
||||||
|
},
|
||||||
|
},
|
||||||
Template: TemplateConfig{
|
Template: TemplateConfig{
|
||||||
HeaderPhrases: []string{
|
HeaderPhrases: []string{
|
||||||
"GirlJuice.Inject();",
|
"GirlJuice.Inject();",
|
||||||
@ -74,15 +82,6 @@ func NewConfig() Config {
|
|||||||
|
|
||||||
ActiveCard: DiyHrtListings,
|
ActiveCard: DiyHrtListings,
|
||||||
|
|
||||||
StoreFilter: diyhrt.StoreFilter{
|
|
||||||
Limit: 0,
|
|
||||||
IncludeIds: []int{7},
|
|
||||||
},
|
|
||||||
|
|
||||||
ListingFilter: diyhrt.ListingFilter{
|
|
||||||
FromStores: []int{7},
|
|
||||||
},
|
|
||||||
|
|
||||||
Websites: []Website{
|
Websites: []Website{
|
||||||
{Url: "https://gitea.elara.ws/Hazel/transfem-startpage", Name: "Transfem Startpage", ImageUrl: "https://gitea.elara.ws/assets/img/logo.svg"},
|
{Url: "https://gitea.elara.ws/Hazel/transfem-startpage", Name: "Transfem Startpage", ImageUrl: "https://gitea.elara.ws/assets/img/logo.svg"},
|
||||||
},
|
},
|
||||||
@ -90,15 +89,15 @@ func NewConfig() Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *TemplateConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
func (c *Config) LoadDiyHrt(listings []diyhrt.Listing) {
|
||||||
existingStores := make(map[int]diyhrt.Store)
|
existingStores := make(map[int]diyhrt.Store)
|
||||||
|
|
||||||
for _, listing := range listings {
|
for _, listing := range listings {
|
||||||
existingStores[listing.Store.Id] = listing.Store
|
existingStores[listing.Store.Id] = listing.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.Listings = rc.ListingFilter.Filter(listings)
|
c.Template.Listings = c.DiyHrt.ListingFilter.Filter(listings)
|
||||||
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
|
c.Template.Stores = c.DiyHrt.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Config) ScanForConfigFile(profile string) error {
|
func (rc *Config) ScanForConfigFile(profile string) error {
|
||||||
|
2
main.go
2
main.go
@ -25,7 +25,7 @@ func FetchDiyHrt() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
CurrentConfig.Template.LoadDiyHrt(l)
|
CurrentConfig.LoadDiyHrt(l)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
tmp/build-errors.log
Normal file
1
tmp/build-errors.log
Normal file
@ -0,0 +1 @@
|
|||||||
|
exit status 1
|
Loading…
x
Reference in New Issue
Block a user