Making config a package within the server

This commit is contained in:
Denis-Cosmin Nutiu 2017-11-26 22:06:45 +02:00
parent 62d871b44c
commit 99ef1b0ea0
3 changed files with 10 additions and 9 deletions

View file

@ -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)
}

View file

@ -1,4 +1,4 @@
package server
package config
import (
"testing"

View file

@ -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)