oc-lib/models/models.go
2024-07-18 13:35:14 +02:00

39 lines
1.0 KiB
Go

package models
import (
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
r "cloud.o-forge.io/core/oc-lib/models/resources"
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
dc "cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
"cloud.o-forge.io/core/oc-lib/models/utils"
w "cloud.o-forge.io/core/oc-lib/models/workflow"
)
var models = map[string]utils.DBObject{
w.WORKFLOW: &w.Workflow{},
r.ToString(r.DATA): &d.Data{},
r.ToString(r.DATACENTER): &dc.Datacenter{},
r.ToString(r.STORAGE): &s.Storage{},
r.ToString(r.PROCESSING): &p.Processing{},
}
func Model(model string) utils.DBObject {
log := logs.CreateLogger("oclib", "")
if _, ok := models[model]; ok {
return models[model]
}
log.Error().Msg("Can't find model " + model + ".")
return nil
}
func Init() {
dbs := []string{}
for db := range models {
dbs = append(dbs, db)
}
mongo.MONGOService.Init(dbs)
}