Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Tiwari <[email protected]>
  • Loading branch information
Revolyssup committed Oct 31, 2022
1 parent 5330cec commit d2cba67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
23 changes: 11 additions & 12 deletions models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package v1alpha1
const ComponentDefinitionKindKey = "ComponentDefinition"

type TypeMeta struct {
Kind string `json:"kind,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind"`
APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion"`
}

// use NewComponent function for instantiating
type Component struct {
TypeMeta `gorm:"embedded"`
ComponentSpec `gorm:"embedded"`
Metadata map[string]interface{} `json:"metadata,omitempty" gorm:"type:JSONB"`
TypeMeta `gorm:"embedded" yaml:"typemeta"`
ComponentSpec `gorm:"embedded" yaml:"componentspec"`
Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata"`
// for backward compatibility
Spec string `json:"spec,omitempty"`
Spec string `json:"spec,omitempty" yaml:"spec"`
}
type capability struct {
ID string `json:"id,omitempty"`
type Capability struct {
// Host is the address of the service registering the capability
Host string `json:"host,omitempty"`
Host string `json:"host,omitempty" yaml:"host"`
}
type ComponentSpec struct {
Schematic map[string]interface{} `json:"schematic,omitempty" gorm:"type:JSONB"`
Schematic map[string]interface{} `json:"schematic,omitempty" yaml:"schematic"`
}

func NewComponent() Component {
Expand All @@ -33,6 +32,6 @@ func NewComponent() Component {
}

type ComponentCapability struct {
Component
capability
Component `yaml:"component"`
Capability `yaml:"capability"`
}
12 changes: 4 additions & 8 deletions models/meshmodel/core/v1alpha1/component_capabilities_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
)

// This file consists of methods and structs that database(gorm) will use to interact with meshmodel components
// This file consists of helper methods and structs that database(gorm) will use to interact with meshmodel components
type ComponentDB struct {
TypeMeta
ComponentSpecDB
Expand All @@ -22,15 +22,11 @@ type ComponentSpecDB struct {
type ComponentCapabilityDB struct {
ID uuid.UUID `json:"id,omitempty"`
ComponentDB
capability
}
type capabilityDB struct {
// Host is the address of the service registering the capability
Host string `json:"host,omitempty"`
Capability
}

func ComponentCapabilityFromCCDB(cdb ComponentCapabilityDB) (c ComponentCapability) {
c.capability = cdb.capability
c.Capability = cdb.Capability
c.TypeMeta = cdb.TypeMeta
c.Spec = cdb.Spec
m := make(map[string]interface{})
Expand All @@ -42,7 +38,7 @@ func ComponentCapabilityFromCCDB(cdb ComponentCapabilityDB) (c ComponentCapabili
return
}
func ComponentCapabilityDBFromCC(c ComponentCapability) (cdb ComponentCapabilityDB) {
cdb.capability = c.capability
cdb.Capability = c.Capability
cdb.TypeMeta = c.TypeMeta
cdb.Spec = c.Spec
cdb.Metadata, _ = json.Marshal(c.Metadata)
Expand Down

0 comments on commit d2cba67

Please sign in to comment.