oc-lib/models/models.go

39 lines
862 B
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package models
import (
oclib "oc-lib"
2024-07-18 12:05:32 +02:00
"oc-lib/dbs/mongo"
2024-07-18 11:51:12 +02:00
r "oc-lib/models/resources"
d "oc-lib/models/resources/data"
dc "oc-lib/models/resources/datacenter"
p "oc-lib/models/resources/processing"
s "oc-lib/models/resources/storage"
"oc-lib/models/utils"
w "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 := oclib.CreateLogger("oclib", "")
if _, ok := models[model]; ok {
return models[model]
}
log.Error().Msg("Can't find model " + model + ".")
return nil
}
2024-07-18 12:05:32 +02:00
func Init() {
dbs := []string{}
for db := range models {
dbs = append(dbs, db)
}
mongo.Init(dbs)
}