40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"cloud.o-forge.io/core/oc-lib/logs"
|
|
|
|
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"
|
|
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
|
)
|
|
|
|
var models = map[string]func() utils.DBObject{
|
|
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
|
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
|
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
|
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
|
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
|
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
|
}
|
|
|
|
func Model(model int) utils.DBObject {
|
|
log := logs.GetLogger()
|
|
if _, ok := models[utils.FromInt(model)]; ok {
|
|
return models[utils.FromInt(model)]()
|
|
}
|
|
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
|
|
return nil
|
|
}
|
|
|
|
func GetModelsNames() []string {
|
|
names := []string{}
|
|
for name := range models {
|
|
names = append(names, name)
|
|
}
|
|
return names
|
|
}
|