Working on using new data model
This commit is contained in:
130
descriptors.go
Normal file
130
descriptors.go
Normal file
@@ -0,0 +1,130 @@
|
||||
package main
|
||||
|
||||
var DescriptorTree = createDescriptorTree(DescriptorRoot{
|
||||
AssetTypes: []AssetType{
|
||||
{
|
||||
Id: "asset",
|
||||
Table: "assets",
|
||||
Name: "General Information",
|
||||
Abstract: true,
|
||||
Fields: []AssetField{
|
||||
{
|
||||
Id: "qr",
|
||||
Name: "QR Code",
|
||||
Type: Number,
|
||||
},
|
||||
{
|
||||
Id: "type",
|
||||
Name: "Type",
|
||||
Type: Type,
|
||||
},
|
||||
{
|
||||
Id: "brand",
|
||||
Name: "Brand",
|
||||
Type: Selection,
|
||||
},
|
||||
{
|
||||
Id: "name",
|
||||
Name: "Name",
|
||||
Type: String,
|
||||
},
|
||||
{
|
||||
Id: "description",
|
||||
Name: "Description",
|
||||
Type: String,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "ram",
|
||||
Name: "Random Access Memory",
|
||||
Table: "info_ram",
|
||||
Fields: []AssetField{
|
||||
{
|
||||
Id: "type",
|
||||
Name: "Type",
|
||||
Type: String,
|
||||
},
|
||||
{
|
||||
Id: "capacity",
|
||||
Name: "Capacity",
|
||||
Type: Capacity,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "hdd",
|
||||
Name: "Hard Disk Drive",
|
||||
Table: "info_hdd",
|
||||
Fields: []AssetField{
|
||||
{
|
||||
Id: "type",
|
||||
Name: "Type",
|
||||
Type: Selection,
|
||||
},
|
||||
{
|
||||
Id: "capacity",
|
||||
Name: "Capacity",
|
||||
Type: Capacity,
|
||||
},
|
||||
{
|
||||
Id: "form_factor",
|
||||
Name: "Form Factor",
|
||||
Type: Selection,
|
||||
},
|
||||
{
|
||||
Id: "interface",
|
||||
Name: "Interface",
|
||||
Type: Selection,
|
||||
},
|
||||
{
|
||||
Id: "rpm",
|
||||
Name: "RPM",
|
||||
Type: Selection,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
func createDescriptorTree(tree DescriptorRoot) *DescriptorRoot {
|
||||
return &tree
|
||||
}
|
||||
|
||||
func getAssetTypeById(id string) *AssetType {
|
||||
for _, assetType := range DescriptorTree.AssetTypes {
|
||||
if assetType.Id == id {
|
||||
return &assetType
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DescriptorRoot struct {
|
||||
AssetTypes []AssetType
|
||||
}
|
||||
|
||||
type AssetType struct {
|
||||
Id string
|
||||
Name string
|
||||
Table string
|
||||
Fields []AssetField
|
||||
Abstract bool
|
||||
}
|
||||
|
||||
type AssetField struct {
|
||||
Id string
|
||||
Name string
|
||||
Type FieldType
|
||||
}
|
||||
|
||||
type FieldType string
|
||||
|
||||
const (
|
||||
Number FieldType = "number"
|
||||
String = "string"
|
||||
Type = "type"
|
||||
Selection = "selection"
|
||||
Bool = "bool"
|
||||
Capacity = "capacity"
|
||||
)
|
||||
Reference in New Issue
Block a user