Add documentation
This commit is contained in:
1 parent
69d0bdabf4
commit
6dab89a1d4
144 files changed
+1107
-549
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
// Internal function to check the system configuration.
|
||||
func checkConfiguration() {
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameDATABASE, `Check now the configuration database.`)
|
||||
defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameDATABASE, `Done checking the configuration database.`)
|
||||
@@ -53,15 +54,14 @@ func checkConfiguration() {
|
||||
Disallow:`)
|
||||
}
|
||||
|
||||
/*
|
||||
Use this function to ensure that the database contains at least a default value for the configuration.
|
||||
*/
|
||||
// Use this function to ensure that the database contains at least a default value for the configuration.
|
||||
func CheckSingleConfigurationPresentsAndAddIfMissing(name, value string) {
|
||||
if !checkSingleConfigurationPresents(name) {
|
||||
addSingleConfiguration(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a configuration value is present.
|
||||
func checkSingleConfigurationPresents(name string) (result bool) {
|
||||
selection := bson.D{{"Name", name}}
|
||||
count, _ := collection.Find(selection).Count()
|
||||
@@ -69,6 +69,7 @@ func checkSingleConfigurationPresents(name string) (result bool) {
|
||||
return count > 0
|
||||
}
|
||||
|
||||
// Adds a configuration value.
|
||||
func addSingleConfiguration(name, value string) {
|
||||
entry := ConfigurationDBEntry{}
|
||||
entry.Name = name
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"gopkg.in/mgo.v2"
|
||||
)
|
||||
|
||||
// The init function for this package.
|
||||
func init() {
|
||||
|
||||
config := Configuration.Read()
|
||||
|
||||
// Connect to MongoDB:
|
||||
@@ -40,6 +40,8 @@ func init() {
|
||||
// Take care about the index:
|
||||
collection.EnsureIndexKey(`Name`)
|
||||
|
||||
// Check the system configuration:
|
||||
checkConfiguration()
|
||||
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameDATABASE, `The configuration database is now ready.`)
|
||||
}
|
||||
@@ -6,9 +6,7 @@ import (
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
/*
|
||||
This function reads the current configuration value.
|
||||
*/
|
||||
// This function reads the current configuration value.
|
||||
func Read(name string) (value string) {
|
||||
if name == `` {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to read a configuration out of the database.`, `The given name was nil!`)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ConfigurationDB
|
||||
|
||||
// The type for a configuration entry.
|
||||
type ConfigurationDBEntry struct {
|
||||
Name string `bson:"Name"`
|
||||
Value string `bson:"Value"`
|
||||
|
||||
@@ -5,15 +5,11 @@ import (
|
||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||
)
|
||||
|
||||
/*
|
||||
Do not use this type by your own! It is a Ocean internal type to provide a shutdown function for the configuration database.
|
||||
*/
|
||||
// The type for the shutdown function.
|
||||
type ShutdownFunction struct {
|
||||
}
|
||||
|
||||
/*
|
||||
If the Ocean server is shutting down, this function is called to close the database.
|
||||
*/
|
||||
// If the Ocean server is shutting down, this function is called to close the database.
|
||||
func (a ShutdownFunction) Shutdown() {
|
||||
Log.LogShort(senderName, LM.CategoryAPP, LM.LevelWARN, LM.MessageNameSHUTDOWN, `Close now the configuration database connection.`)
|
||||
db.Logout()
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
session *mgo.Session = nil
|
||||
db *mgo.Database = nil
|
||||
collection *mgo.Collection = nil
|
||||
config Meta.Configuration = Meta.Configuration{}
|
||||
senderName LM.Sender = `System::ConfigurationDB`
|
||||
session *mgo.Session = nil // The database session
|
||||
db *mgo.Database = nil // The database
|
||||
collection *mgo.Collection = nil // The database collection
|
||||
config Meta.Configuration = Meta.Configuration{} // The configuration file's data
|
||||
senderName LM.Sender = `System::ConfigurationDB` // This is the name for logging event from this package
|
||||
)
|
||||
@@ -6,15 +6,14 @@ import (
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
/*
|
||||
This function writes the configuration value.
|
||||
*/
|
||||
// This function writes the configuration value.
|
||||
func Write(name, value string) {
|
||||
if name == `` {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to write a configuration to the database.`, `The given name was nil!`)
|
||||
return
|
||||
}
|
||||
|
||||
// Read the current value:
|
||||
result := ConfigurationDBEntry{}
|
||||
if errFind := collection.Find(bson.D{{"Name", name}}).One(&result); errFind != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNameDATABASE, `Was not able to write a configuration to the database.`, `Error while find.`, errFind.Error())
|
||||
@@ -22,6 +21,8 @@ func Write(name, value string) {
|
||||
}
|
||||
|
||||
result.Value = value
|
||||
|
||||
// Update the database:
|
||||
collection.Update(bson.D{{"Name", name}}, result)
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user