summaryrefslogtreecommitdiffstats
path: root/0001-Update-directories-fig-searches.patch
blob: 1172d5e69308b8334f2577cda076163d50d35646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 0d47544d12656be9eb853f8323f0da19eec2316c Mon Sep 17 00:00:00 2001
From: Leonardo Bishop <me@leonardobishop.net>
Date: Thu, 7 Aug 2025 12:00:20 +0100
Subject: [PATCH 1/2] Update directories fig searches

---
 walrss/internal/state/state.go | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/walrss/internal/state/state.go b/walrss/internal/state/state.go
index 522e1bf..1fe33ee 100644
--- a/walrss/internal/state/state.go
+++ b/walrss/internal/state/state.go
@@ -3,12 +3,13 @@ package state
 import (
 	"errors"
 	"fmt"
+	"os"
+	"strings"
+
 	"github.com/kkyr/fig"
 	"github.com/rs/zerolog"
 	"github.com/rs/zerolog/log"
 	"github.com/uptrace/bun"
-	"os"
-	"strings"
 )
 
 type State struct {
@@ -48,23 +49,19 @@ type Config struct {
 	Debug bool `fig:"debug"`
 }
 
+const walrssConfigDirEnv = "WALRSS_CONFIG_DIR"
 const configFilename = "config.yaml"
 
 func LoadConfig() (*Config, error) {
-	// If the file doesn't exist, Fig will throw a hissy fit, so we should create a blank one if it doesn't exist
-	if _, err := os.Stat(configFilename); err != nil {
-		if errors.Is(err, os.ErrNotExist) {
-			// If the file doesn't have contents, Fig will throw an EOF, despite `touch config.yaml` working fine. idk lol
-			if err := os.WriteFile(configFilename, []byte("{}"), 0777); err != nil {
-				return nil, err
-			}
-		} else {
-			return nil, err
-		}
+	var configDirs []string
+
+	if config := os.Getenv(walrssConfigDirEnv); config != "" {
+		configDirs = append(configDirs, config)
 	}
+	configDirs = append(configDirs, ".")
 
 	cfg := new(Config)
-	if err := fig.Load(cfg); err != nil {
+	if err := fig.Load(cfg, fig.Dirs(configDirs...), fig.File(configFilename)); err != nil {
 		return nil, err
 	}
 
-- 
2.50.1