refactor: make data path (partially) configurable
Alan Pearce alan@alanpearce.eu
Tue, 07 May 2024 14:21:22 +0200
3 files changed, 6 insertions(+), 4 deletions(-)
M config.toml → config.toml
@@ -1,4 +1,5 @@ base_url = "https://searchix.alanpearce.eu" +data_path = "./data" [content-security-policy] default-src = [
M internal/config/config.go → internal/config/config.go
@@ -24,9 +24,10 @@ return nil } type Config struct { - BaseURL URL `toml:"base_url"` - CSP *CSP `toml:"content-security-policy"` - Headers map[string]string + BaseURL URL `toml:"base_url"` + DataPath string `toml:"data_path"` + CSP *CSP `toml:"content-security-policy"` + Headers map[string]string } func GetConfig() (*Config, error) {
M internal/server/server.go → internal/server/server.go
@@ -183,7 +183,7 @@ } }) var nixosOptions = options.NixOptions{} - jsonFile, err := os.ReadFile(path.Join("data", "test.json")) + jsonFile, err := os.ReadFile(path.Join(config.DataPath, "test.json")) if err != nil { slog.Error(fmt.Sprintf("error reading json file: %v", err)) }