package oclib import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" "cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/models" "cloud.o-forge.io/core/oc-lib/models/resources" "cloud.o-forge.io/core/oc-lib/models/utils" "github.com/rs/zerolog" ) type LibDataEnum int const ( INVALID LibDataEnum = iota DATA = resources.DATA PROCESSING = resources.PROCESSING STORAGE = resources.STORAGE DATACENTER = resources.DATACENTER WORKFLOW = resources.WORKFLOW ) func (d LibDataEnum) EnumIndex() int { return int(d) } type LibData struct { Data utils.DBObject `bson:"data" json:"data"` Err error `bson:"error" json:"error"` } func Init(appName string) { logs.SetAppName(appName) logs.SetLogger(logs.CreateLogger("main", "")) mongo.MONGOService.Init(models.GetModelsNames(), GetConfig()) } func GetLogger() zerolog.Logger { return logs.GetLogger() } func LoadOne(collection LibDataEnum, id string) LibData { d, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id) return LibData{Data: d, Err: err} } func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData { d, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id) return LibData{Data: d, Err: err} } func DeleteOne(collection LibDataEnum, id string) LibData { d, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id) return LibData{Data: d, Err: err} } func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData { model := models.Model(collection.EnumIndex()) d, err := model.GetAccessor().StoreOne(model.Deserialize(object)) return LibData{Data: d, Err: err} }