Ocean/Configuration/ReadConfiguration.go
Thorsten Sommer f33f7b5c29 Refactoring, Bugfix & Updates
+ Refactored all imports
+ Fixed a bug for the logging regarding removing \n \t \r
+ Updated to current MGO release
+ Changed the name of ICCC
2014-10-19 19:19:11 +02:00

55 lines
1.6 KiB
Go

package Configuration
import (
"encoding/json"
"github.com/SommerEngineering/Ocean/Log"
"github.com/SommerEngineering/Ocean/Log/Meta"
"os"
"path/filepath"
)
func readConfiguration() {
if isInit {
Log.LogFull(senderName, Meta.CategorySYSTEM, Meta.LevelWARN, Meta.SeverityNone, Meta.ImpactNone, Meta.MessageNameINIT, `The configuration package is already init!`)
return
} else {
Log.LogShort(senderName, Meta.CategorySYSTEM, Meta.LevelINFO, Meta.MessageNameCONFIGURATION, `Init of configuration starting.`)
}
currentDir, dirError := os.Getwd()
if dirError != nil {
panic(`Was not able to read the working directory: ` + dirError.Error())
return
}
currentPath := filepath.Join(currentDir, filename)
if _, errFile := os.Stat(currentPath); errFile != nil {
if os.IsNotExist(errFile) {
panic(`It was not possible to find the necessary configuration file 'configuration.json' at the application directory.`)
} else {
panic(`There was an error while open the configuration: ` + errFile.Error())
}
}
file, fileError := os.Open(currentPath)
defer file.Close()
if fileError != nil {
panic(`The configuration file is not accessible: ` + fileError.Error())
return
}
decoder := json.NewDecoder(file)
decError := decoder.Decode(&configuration)
if decError != nil {
panic(`Decoding of the configuration file was not possible: ` + decError.Error())
}
Log.LogShort(senderName, Meta.CategorySYSTEM, Meta.LevelINFO, Meta.MessageNameINIT, `Init of configuration is done.`)
isInit = true
return
}