Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"gopkg.in/yaml.v3"
"os"
"rclone-manager/internal/constants"
"rclone-manager/internal/environment"
)

type Config struct {
Expand All @@ -22,7 +23,8 @@ type Config struct {
}

func LoadConfig() (*Config, error) {
data, err := os.ReadFile(constants.YAMLPath)
yamlPath := environment.GetEnvWithFallback(constants.YAMLPathEnvVar, constants.DefaultYAMLPath)
data, err := os.ReadFile(yamlPath)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions src/internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (

// Constants data files
const (
YAMLPath = "/data/config.yaml"
RcloneConf = "/data/rclone.conf"
YAMLPathEnvVar = "RCLONE_MANAGER_CONFIG_YAML"
DefaultYAMLPath = "/data/config.yaml"
RcloneConfEnvVar = "RCLONE_MANAGER_RCLONE_CONF"
DefaultRcloneConf = "/data/rclone.conf"
)
8 changes: 8 additions & 0 deletions src/internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ func PrepareEnvironment(envVars map[string]string) []string {
return mapToSlice(envMap)
}

func GetEnvWithFallback(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}

func splitEnv(env string) []string {
parts := make([]string, 2)
idx := strings.Index(env, "=")
Expand Down
8 changes: 6 additions & 2 deletions src/internal/rclone_manager/rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/rs/zerolog"
"rclone-manager/internal/config"
"rclone-manager/internal/constants"
"rclone-manager/internal/environment"
"rclone-manager/internal/mount_manager"
"rclone-manager/internal/serve_manager"
"rclone-manager/internal/watcher"
Expand Down Expand Up @@ -41,9 +42,12 @@ func InitializeRClone(logger zerolog.Logger) {
go mount_manager.InitializeMountEndpoints(conf, logger, &processLock)
}

yamlPath := environment.GetEnvWithFallback(constants.YAMLPathEnvVar, constants.DefaultYAMLPath)
rcloneConfPath := environment.GetEnvWithFallback(constants.RcloneConfEnvVar, constants.DefaultRcloneConf)

filesToWatch := []string{
constants.YAMLPath,
constants.RcloneConf,
yamlPath,
rcloneConfPath,
}

watcher.StartNewFileWatcher(filesToWatch, reloadConfig, logger)
Expand Down
Loading