oc-lib/models/models.go
2024-07-18 14:39:54 +02:00

38 lines
1.2 KiB
Go

package models
import (
"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]func() utils.DBObject{
w.WORKFLOW: func() utils.DBObject { return &w.Workflow{} },
r.ToString(r.DATA): func() utils.DBObject { return &d.Data{} },
r.ToString(r.DATACENTER): func() utils.DBObject { return &dc.Datacenter{} },
r.ToString(r.STORAGE): func() utils.DBObject { return &s.Storage{} },
r.ToString(r.PROCESSING): func() utils.DBObject { return &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 GetModelsNames() []string {
names := []string{}
for name := range models {
names = append(names, name)
}
return names
}