86 lines
2.5 KiB
Go
86 lines
2.5 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"cloud.o-forge.io/core/oc-catalog/models"
|
||
|
"github.com/mitchellh/mapstructure"
|
||
|
)
|
||
|
|
||
|
// This module allows us to :
|
||
|
// - Reduce the size of graph.go
|
||
|
// - apply specific object construction logic depending on the component's type
|
||
|
|
||
|
// So far the unpacking of json/map data into the models has the caveat of not applying to the nested struct
|
||
|
|
||
|
func ConstructComputingObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (computing models.ComputingModel) {
|
||
|
|
||
|
computing.ID = id
|
||
|
err := mapstructure.Decode(component_info,&computing.ComputingNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Computing : Error unpacking json into objects info")
|
||
|
log.Err(err)
|
||
|
}
|
||
|
|
||
|
err = mapstructure.Decode(user_inputs,&computing.ComputingNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Computing : Error unpacking data input into comp object")
|
||
|
log.Err(err).Msg(err.Error())
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func ConstructDataObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (data models.DataModel) {
|
||
|
|
||
|
data.ID = id
|
||
|
err := mapstructure.Decode(component_info,&data.DataNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Data: Error unpacking json into objects info")
|
||
|
log.Err(err)
|
||
|
}
|
||
|
|
||
|
err = mapstructure.Decode(user_inputs,&data.DataNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Data: Error unpacking data input into comp object")
|
||
|
log.Err(err).Msg(err.Error())
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func ConstructDatacenterObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (datacenter models.DatacenterModel) {
|
||
|
|
||
|
datacenter.ID = id
|
||
|
err := mapstructure.Decode(component_info,&datacenter.DatacenterNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Datacenter: Error unpacking json into objects info")
|
||
|
log.Err(err)
|
||
|
}
|
||
|
|
||
|
err = mapstructure.Decode(user_inputs,&datacenter.DatacenterNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Datacenter: Error unpacking data input into comp object")
|
||
|
log.Err(err).Msg(err.Error())
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func ConstructStorageObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (storage models.StorageModel) {
|
||
|
|
||
|
storage.ID = id
|
||
|
err := mapstructure.Decode(component_info,&storage.StorageNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Storage: Error unpacking json into objects info")
|
||
|
log.Err(err)
|
||
|
}
|
||
|
|
||
|
err = mapstructure.Decode(user_inputs,&storage.StorageNEWModel)
|
||
|
if err != nil {
|
||
|
fmt.Println("Storage: Error unpacking data input into comp object")
|
||
|
log.Err(err).Msg(err.Error())
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|