Making config a package within the server
This commit is contained in:
parent
62d871b44c
commit
99ef1b0ea0
3 changed files with 10 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
// This file contains the configuration settings for the server.
|
// This file contains the configuration settings for the server.
|
||||||
package server
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
@ -38,7 +38,7 @@ func setDefaultConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializedConfiguration initializes the configuration for the application.
|
// 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.StringVar(&ConfigPath, "config", ".", "Set the location of the config file.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -46,9 +46,5 @@ func InitializedConfiguration() {
|
||||||
loadConfigFromFile()
|
loadConfigFromFile()
|
||||||
|
|
||||||
viper.WatchConfig()
|
viper.WatchConfig()
|
||||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
viper.OnConfigChange(callback)
|
||||||
log.Println("Reloaded configuration file successfully!")
|
|
||||||
})
|
|
||||||
|
|
||||||
BasePath = viper.GetString("absoluteServePath")
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"github.com/metonimie/simpleFTP/server/server/config"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -87,11 +89,14 @@ func HandleConnection(client Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartFtpServer() {
|
func StartFtpServer() {
|
||||||
InitializedConfiguration()
|
config.InitializedConfiguration(func(e fsnotify.Event) {
|
||||||
|
log.Println("Configuration reloaded!")
|
||||||
|
})
|
||||||
|
|
||||||
Addr := viper.GetString("address")
|
Addr := viper.GetString("address")
|
||||||
Port := viper.GetString("port")
|
Port := viper.GetString("port")
|
||||||
DirDepth := viper.GetInt("maxDirDepth")
|
DirDepth := viper.GetInt("maxDirDepth")
|
||||||
|
BasePath = viper.GetString("absoluteServePath")
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
listener, err := net.Listen("tcp", Addr+":"+Port)
|
listener, err := net.Listen("tcp", Addr+":"+Port)
|
||||||
|
|
Loading…
Reference in a new issue