This commit is contained in:
mr
2024-07-18 15:15:01 +02:00
parent 33c284cd4c
commit 6d104288b7
3 changed files with 40 additions and 25 deletions

View File

@@ -12,19 +12,19 @@ import (
)
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{} },
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{} },
}
func Model(model string) utils.DBObject {
func Model(model int) utils.DBObject {
log := logs.CreateLogger("oclib", "")
if _, ok := models[model]; ok {
return models[model]()
if _, ok := models[r.FromInt(model)]; ok {
return models[r.FromInt(model)]()
}
log.Error().Msg("Can't find model " + model + ".")
log.Error().Msg("Can't find model " + r.FromInt(model) + ".")
return nil
}

View File

@@ -26,8 +26,17 @@ var str = [...]string{
"workflow",
}
func ToString(r ResourceType) string {
return str[r]
func FromInt(i int) string {
return str[i]
}
func (d ResourceType) String() string {
return str[d]
}
// EnumIndex - Creating common behavior-give the type a EnumIndex functio
func (d ResourceType) EnumIndex() int {
return int(d)
}
type Resource interface {