oc-lib/models/models.go

38 lines
1.2 KiB
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package models
import (
2024-07-18 13:35:14 +02:00
"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"
2024-07-18 11:51:12 +02:00
)
2024-07-18 14:39:54 +02:00
var models = map[string]func() utils.DBObject{
2024-07-18 15:15:01 +02:00
w.WORKFLOW: 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{} },
2024-07-18 11:51:12 +02:00
}
2024-07-18 15:15:01 +02:00
func Model(model int) utils.DBObject {
2024-07-18 13:35:14 +02:00
log := logs.CreateLogger("oclib", "")
2024-07-18 15:15:01 +02:00
if _, ok := models[r.FromInt(model)]; ok {
return models[r.FromInt(model)]()
2024-07-18 11:51:12 +02:00
}
2024-07-18 15:15:01 +02:00
log.Error().Msg("Can't find model " + r.FromInt(model) + ".")
2024-07-18 11:51:12 +02:00
return nil
}
2024-07-18 12:05:32 +02:00
2024-07-18 14:11:13 +02:00
func GetModelsNames() []string {
names := []string{}
for name := range models {
names = append(names, name)
2024-07-18 12:05:32 +02:00
}
2024-07-18 14:11:13 +02:00
return names
2024-07-18 12:05:32 +02:00
}