all repos — searchix @ f272e269787f0db46d8f90c7ec2cd37e6d4e299a

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor: make data path (partially) configurable
Alan Pearce alan@alanpearce.eu
Tue, 07 May 2024 14:21:22 +0200
commit

f272e269787f0db46d8f90c7ec2cd37e6d4e299a

parent

9b24b805b45c71bb54dacc1112380357050f48af

3 files changed, 6 insertions(+), 4 deletions(-)

jump to
M config.tomlconfig.toml
@@ -1,4 +1,5 @@ base_url = "https://searchix.alanpearce.eu"
+data_path = "./data"
 
 [content-security-policy]
 default-src = [
M internal/config/config.gointernal/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.gointernal/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))
 	}