added scanning for config file
This commit is contained in:
parent
68522efb18
commit
45111321b2
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.24.2
|
|||||||
require github.com/labstack/echo/v4 v4.13.4
|
require github.com/labstack/echo/v4 v4.13.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f // indirect
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
github.com/labstack/gommon v0.4.2 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -2,6 +2,8 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg
|
|||||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU=
|
||||||
|
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0=
|
||||||
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
|
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
|
||||||
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
|
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
|
||||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package rendering
|
package rendering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/pelletier/go-toml"
|
|
||||||
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
"gitea.elara.ws/Hazel/transfem-startpage/internal/diyhrt"
|
||||||
|
"github.com/kirsle/configdir"
|
||||||
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RenderingConfig struct {
|
type RenderingConfig struct {
|
||||||
@ -65,9 +69,36 @@ func (rc *RenderingConfig) LoadDiyHrt(listings []diyhrt.Listing) {
|
|||||||
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
|
rc.Stores = rc.StoreFilter.Filter(slices.Collect(maps.Values(existingStores)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RenderingConfig) LoadConfigFile(file string) error {
|
|
||||||
|
func (rc *RenderingConfig) ScanForConfigFile(profile string) error {
|
||||||
|
profileFile := profile + ".toml"
|
||||||
|
|
||||||
|
configPath := configdir.LocalConfig("startpage")
|
||||||
|
configFile := filepath.Join(configPath, profileFile)
|
||||||
|
|
||||||
|
if err := rc.LoadConfigFile(configFile); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rc.LoadConfigFile(profileFile); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rc.LoadConfigFile("." + profileFile); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("No config file found")
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *RenderingConfig) LoadConfigFile(file string) error {
|
func (rc *RenderingConfig) LoadConfigFile(file string) error {
|
||||||
|
if _, err := os.Stat(file); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("loading config file: " + file)
|
||||||
|
|
||||||
|
|
||||||
content, err := os.ReadFile(file)
|
content, err := os.ReadFile(file)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
main.go
2
main.go
@ -42,7 +42,7 @@ func getIndex(c echo.Context) error {
|
|||||||
func main() {
|
func main() {
|
||||||
fmt.Println("running transfem startpage")
|
fmt.Println("running transfem startpage")
|
||||||
|
|
||||||
CurrentRenderingConfig.LoadConfigFile("config.toml")
|
CurrentRenderingConfig.ScanForConfigFile("startpage")
|
||||||
|
|
||||||
err := FetchDiyHrt()
|
err := FetchDiyHrt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1 +1 @@
|
|||||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
Loading…
x
Reference in New Issue
Block a user