File tree Expand file tree Collapse file tree 4 files changed +21
-5
lines changed
Expand file tree Collapse file tree 4 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 44 "gopkg.in/yaml.v3"
55 "os"
66 "rclone-manager/internal/constants"
7+ "rclone-manager/internal/environment"
78)
89
910type Config struct {
@@ -22,7 +23,8 @@ type Config struct {
2223}
2324
2425func LoadConfig () (* Config , error ) {
25- data , err := os .ReadFile (constants .YAMLPath )
26+ yamlPath := environment .GetEnvWithFallback (constants .YAMLPathEnvVar , constants .DefaultYAMLPath )
27+ data , err := os .ReadFile (yamlPath )
2628 if err != nil {
2729 return nil , err
2830 }
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ const (
2828
2929// Constants data files
3030const (
31- YAMLPath = "/data/config.yaml"
32- RcloneConf = "/data/rclone.conf"
31+ YAMLPathEnvVar = "RCLONE_MANAGER_CONFIG_YAML"
32+ DefaultYAMLPath = "/data/config.yaml"
33+ RcloneConfEnvVar = "RCLONE_MANAGER_RCLONE_CONF"
34+ DefaultRcloneConf = "/data/rclone.conf"
3335)
Original file line number Diff line number Diff line change @@ -25,6 +25,14 @@ func PrepareEnvironment(envVars map[string]string) []string {
2525 return mapToSlice (envMap )
2626}
2727
28+ func GetEnvWithFallback (key , defaultValue string ) string {
29+ value := os .Getenv (key )
30+ if value == "" {
31+ return defaultValue
32+ }
33+ return value
34+ }
35+
2836func splitEnv (env string ) []string {
2937 parts := make ([]string , 2 )
3038 idx := strings .Index (env , "=" )
Original file line number Diff line number Diff line change 44 "github.com/rs/zerolog"
55 "rclone-manager/internal/config"
66 "rclone-manager/internal/constants"
7+ "rclone-manager/internal/environment"
78 "rclone-manager/internal/mount_manager"
89 "rclone-manager/internal/serve_manager"
910 "rclone-manager/internal/watcher"
@@ -41,9 +42,12 @@ func InitializeRClone(logger zerolog.Logger) {
4142 go mount_manager .InitializeMountEndpoints (conf , logger , & processLock )
4243 }
4344
45+ yamlPath := environment .GetEnvWithFallback (constants .YAMLPathEnvVar , constants .DefaultYAMLPath )
46+ rcloneConfPath := environment .GetEnvWithFallback (constants .RcloneConfEnvVar , constants .DefaultRcloneConf )
47+
4448 filesToWatch := []string {
45- constants . YAMLPath ,
46- constants . RcloneConf ,
49+ yamlPath ,
50+ rcloneConfPath ,
4751 }
4852
4953 watcher .StartNewFileWatcher (filesToWatch , reloadConfig , logger )
You can’t perform that action at this time.
0 commit comments