From b50066ef5dbe8600f7ae928b7e26618e49ee9e1f Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 13 Sep 2014 12:56:35 +0200 Subject: [PATCH] Bug fixes and improvements - Bugfix: The configuration collection can not have a key for the values. - Bugfix: It was possible, that the shutdown handler list was init to late. + ConfigDB: It is now possible to write and therefore to change a configuration value. + Added a few more message names for the logger. --- ConfigurationDB/Init.go | 1 - ConfigurationDB/Write.go | 25 +++++++++++++++++++++++++ Log/Meta/MessageNames.go | 4 ++++ Shutdown/Init.go | 5 ++++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 ConfigurationDB/Write.go diff --git a/ConfigurationDB/Init.go b/ConfigurationDB/Init.go index 76cae61..6fb2668 100644 --- a/ConfigurationDB/Init.go +++ b/ConfigurationDB/Init.go @@ -37,7 +37,6 @@ func init() { // Take care about the index: collection.EnsureIndexKey(`Name`) - collection.EnsureIndexKey(`Value`) checkConfiguration() Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameDATABASE, `The configuration database is now ready.`) diff --git a/ConfigurationDB/Write.go b/ConfigurationDB/Write.go new file mode 100644 index 0000000..50f7422 --- /dev/null +++ b/ConfigurationDB/Write.go @@ -0,0 +1,25 @@ +package ConfigurationDB + +import "github.com/SommerEngineering/Ocean/Log" +import LM "github.com/SommerEngineering/Ocean/Log/Meta" +import "labix.org/v2/mgo/bson" + +/* +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 + } + + 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 + collection.Update(bson.D{{"Name", name}}, result) + return +} diff --git a/Log/Meta/MessageNames.go b/Log/Meta/MessageNames.go index ebf9401..1a64940 100644 --- a/Log/Meta/MessageNames.go +++ b/Log/Meta/MessageNames.go @@ -31,4 +31,8 @@ const ( MessageNamePRODUCER = `Producer` MessageNameCONSUMER = `Consumer` MessageNamePASSWORD = `Password` + MessageNamePARSE = `Parse` + MessageNameUSER = `User` + MessageNameREQUEST = `Request` + MessageNameRESPONSE = `Response` ) diff --git a/Shutdown/Init.go b/Shutdown/Init.go index ca3a82b..312f589 100644 --- a/Shutdown/Init.go +++ b/Shutdown/Init.go @@ -4,8 +4,11 @@ import "container/list" import "os/signal" import "os" -func InitShutdown() { +func init() { shutdownHandlers = list.New() +} + +func InitShutdown() { // Apply the shutdown handler: signal.Notify(shutdownSignal, os.Interrupt, os.Kill)