Ocean/ConfigurationDB/Write.go

29 lines
988 B
Go
Raw Permalink Normal View History

package ConfigurationDB
import (
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"gopkg.in/mgo.v2/bson"
)
2015-06-17 15:44:52 +00:00
// 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
}
2015-06-17 15:44:52 +00:00
// 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())
return
}
result.Value = value
2015-06-17 15:44:52 +00:00
// Update the database:
collection.Update(bson.D{{"Name", name}}, result)
return
}