diff --git a/server/server/config.go b/server/server/config/config.go similarity index 86% rename from server/server/config.go rename to server/server/config/config.go index 60e43a7..ca467e0 100644 --- a/server/server/config.go +++ b/server/server/config/config.go @@ -1,5 +1,5 @@ // This file contains the configuration settings for the server. -package server +package config import ( "log" @@ -38,7 +38,7 @@ func setDefaultConfiguration() { } // InitializedConfiguration initializes the configuration for the application. -func InitializedConfiguration() { +func InitializedConfiguration(callback func(e fsnotify.Event)) { flag.StringVar(&ConfigPath, "config", ".", "Set the location of the config file.") flag.Parse() @@ -46,9 +46,5 @@ func InitializedConfiguration() { loadConfigFromFile() viper.WatchConfig() - viper.OnConfigChange(func(e fsnotify.Event) { - log.Println("Reloaded configuration file successfully!") - }) - - BasePath = viper.GetString("absoluteServePath") + viper.OnConfigChange(callback) } diff --git a/server/server/config_test.go b/server/server/config/config_test.go similarity index 98% rename from server/server/config_test.go rename to server/server/config/config_test.go index 0479909..b279100 100644 --- a/server/server/config_test.go +++ b/server/server/config/config_test.go @@ -1,4 +1,4 @@ -package server +package config import ( "testing" diff --git a/server/server/connection.go b/server/server/connection.go index 8c50d31..94487c8 100644 --- a/server/server/connection.go +++ b/server/server/connection.go @@ -7,6 +7,8 @@ import ( "log" "net" + "github.com/fsnotify/fsnotify" + "github.com/metonimie/simpleFTP/server/server/config" "github.com/spf13/viper" ) @@ -87,11 +89,14 @@ func HandleConnection(client Client) { } func StartFtpServer() { - InitializedConfiguration() + config.InitializedConfiguration(func(e fsnotify.Event) { + log.Println("Configuration reloaded!") + }) Addr := viper.GetString("address") Port := viper.GetString("port") DirDepth := viper.GetInt("maxDirDepth") + BasePath = viper.GetString("absoluteServePath") // Start the server listener, err := net.Listen("tcp", Addr+":"+Port)