@@ -3,12 +3,14 @@ package config
33import (
44 "encoding/json"
55 "fmt"
6- "io/ioutil"
76 "os"
87 "path/filepath"
98 "runtime"
109)
1110
11+ // customLogDir is used to override the default log directory, e.g. for testing.
12+ var customLogDir string
13+
1214// SSLConfig represents the SSL configuration for a site.
1315type SSLConfig struct {
1416 Enabled bool `json:"enabled"`
@@ -42,6 +44,10 @@ func GetConfigDir() string {
4244
4345// GetLogDir returns the directory where log files are stored.
4446func GetLogDir () string {
47+ if customLogDir != "" {
48+ return customLogDir
49+ }
50+
4551 var logDir string
4652 if xdgDataHome := os .Getenv ("XDG_DATA_HOME" ); xdgDataHome != "" {
4753 logDir = filepath .Join (xdgDataHome , "goup" , "logs" )
@@ -56,7 +62,7 @@ func GetLogDir() string {
5662// LoadConfig loads a configuration from a file.
5763func LoadConfig (filePath string ) (SiteConfig , error ) {
5864 var conf SiteConfig
59- data , err := ioutil .ReadFile (filePath )
65+ data , err := os .ReadFile (filePath )
6066 if err != nil {
6167 return conf , err
6268 }
@@ -69,7 +75,7 @@ func LoadConfig(filePath string) (SiteConfig, error) {
6975// LoadAllConfigs loads all configurations from the configuration directory.
7076func LoadAllConfigs () ([]SiteConfig , error ) {
7177 configDir := GetConfigDir ()
72- files , err := ioutil .ReadDir (configDir )
78+ files , err := os .ReadDir (configDir )
7379 if err != nil {
7480 return nil , err
7581 }
@@ -94,5 +100,10 @@ func (conf *SiteConfig) Save(filePath string) error {
94100 if err != nil {
95101 return err
96102 }
97- return ioutil .WriteFile (filePath , data , 0644 )
103+ return os .WriteFile (filePath , data , 0644 )
104+ }
105+
106+ // SetCustomLogDir allows setting a custom log directory for testing.
107+ func SetCustomLogDir (dir string ) {
108+ customLogDir = dir
98109}
0 commit comments