Ocean/Log/DeviceDatabase/ReadMessageNamesFromDB.go

30 lines
946 B
Go
Raw Normal View History

2015-06-17 15:44:52 +00:00
package DeviceDatabase
import (
2015-06-22 15:38:55 +00:00
"github.com/SommerEngineering/Ocean/Admin/Scheme"
2015-06-17 15:44:52 +00:00
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"gopkg.in/mgo.v2/bson"
"sort"
)
// Read the message names from the database without any cache.
2015-06-22 15:38:55 +00:00
func readMessageNamesFromDB() (result []Scheme.MessageNames) {
2015-06-17 15:44:52 +00:00
var nextMessageNames []string
2015-06-23 15:22:24 +00:00
if err := logDBCollection.Find(bson.D{{`Project`, projectName}}).Distinct(`MessageName`, &nextMessageNames); err != nil {
2015-06-17 15:44:52 +00:00
// Case: Error, was not able to write the event to the database:
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.MessageNameDATABASE, `Was not able to read the message names from the database.`, err.Error())
return
}
// Sort the sender names:
sort.Strings(nextMessageNames)
2015-06-22 15:38:55 +00:00
// Transform the values to the right format:
for _, entry := range nextMessageNames {
result = append(result, Scheme.MessageNames(entry))
}
2015-06-17 15:44:52 +00:00
return
}