Initial commit of Ocean's local development
This commit is contained in:
1 parent
9944a9e1df
commit
86451938ec
116 files changed
+3320
No files matched your search
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
This package reads the configuration file from the disk (file: configuration.json).
|
||||
This configuratin is just used to specific the configuration database to go further.
|
||||
|
||||
An example configuration.json file:
|
||||
|
||||
{
|
||||
"ConfigDBHostname" : "localhost:27017",
|
||||
"ConfigDBDatabase" : "MyDatabase",
|
||||
"ConfigDBConfigurationCollection" : "Configuration",
|
||||
"ConfigDBConfigurationCollectionUsername" : "ConfigurationUsername",
|
||||
"ConfigDBConfigurationCollectionPassword" : "ConfigurationPassword"
|
||||
}
|
||||
|
||||
Hint #1: Ocean is using MongoDB as database ;-)
|
||||
Hint #2: Normally, you do not use this package at all, because the application configuration should persist
|
||||
inside the configuration database. Your task: Provide a configuration.json file at the installation directory ;-)
|
||||
*/
|
||||
package Configuration
|
||||
@@ -0,0 +1,6 @@
|
||||
package Configuration
|
||||
|
||||
func init() {
|
||||
readConfiguration()
|
||||
isInit = true
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package Meta
|
||||
|
||||
// The type which matches the configuration file:
|
||||
type Configuration struct {
|
||||
ConfigDBHostname string
|
||||
ConfigDBDatabase string
|
||||
ConfigDBConfigurationCollection string
|
||||
ConfigDBConfigurationCollectionUsername string
|
||||
ConfigDBConfigurationCollectionPassword string
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package Configuration
|
||||
|
||||
import "github.com/SommerEngineering/Ocean/Configuration/Meta"
|
||||
|
||||
/*
|
||||
Read the whole configuration and enable Ocean to get the configuration database.
|
||||
|
||||
Hint: Normally, you do not use this package at all, because the application configuration should persist
|
||||
inside the configuration database.
|
||||
*/
|
||||
func Read() (result Meta.Configuration) {
|
||||
result = configuration
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package Configuration
|
||||
|
||||
import "encoding/json"
|
||||
import "os"
|
||||
import "path/filepath"
|
||||
import "github.com/SommerEngineering/Ocean/Log"
|
||||
import "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package Configuration
|
||||
|
||||
import "github.com/SommerEngineering/Ocean/Configuration/Meta"
|
||||
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
|
||||
var (
|
||||
filename = "configuration.json" // Where is the configuration located?
|
||||
configuration Meta.Configuration = Meta.Configuration{} // The loaded configuration
|
||||
isInit = false // Is the configuration loaded?
|
||||
senderName LM.Sender = `System::Configuration`
|
||||
)
|
||||
Reference in new issue
Block a user