oc-lib/models/models.go
2024-07-18 17:55:27 +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"
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
var models = map[string]func() utils.DBObject{
r.WORKFLOW.String(): func() utils.DBObject { return &w.Workflow{} },
r.DATA.String(): func() utils.DBObject { return &d.Data{} },
r.DATACENTER.String(): func() utils.DBObject { return &dc.Datacenter{} },
r.STORAGE.String(): func() utils.DBObject { return &s.Storage{} },
r.PROCESSING.String(): func() utils.DBObject { return &p.Processing{} },
}
func Model(model int) utils.DBObject {
log := logs.GetLogger()
if _, ok := models[r.FromInt(model)]; ok {
return models[r.FromInt(model)]()
}
log.Error().Msg("Can't find model " + r.FromInt(model) + ".")
return nil
}
func GetModelsNames() []string {
names := []string{}
for name := range models {
names = append(names, name)
}
return names
}