generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Database compliant Meshmodel structs
Signed-off-by: revolyssup <ashishjaitiwari15112000@gmail.com>
- Loading branch information
1 parent
c34ac46
commit 5330cec
Showing
2 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
models/meshmodel/core/v1alpha1/component_capabilities_db.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
// This file consists of methods and structs that database(gorm) will use to interact with meshmodel components | ||
type ComponentDB struct { | ||
TypeMeta | ||
ComponentSpecDB | ||
Metadata []byte `json:"metadata"` | ||
// for backward compatibility | ||
Spec string `json:"spec,omitempty"` | ||
} | ||
|
||
type ComponentSpecDB struct { | ||
Schematic []byte `json:"schematic,omitempty"` | ||
} | ||
|
||
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"` | ||
} | ||
|
||
func ComponentCapabilityFromCCDB(cdb ComponentCapabilityDB) (c ComponentCapability) { | ||
c.capability = cdb.capability | ||
c.TypeMeta = cdb.TypeMeta | ||
c.Spec = cdb.Spec | ||
m := make(map[string]interface{}) | ||
json.Unmarshal(cdb.Metadata, &m) | ||
c.Metadata = m | ||
schematic := make(map[string]interface{}) | ||
json.Unmarshal(cdb.Schematic, &schematic) | ||
c.Schematic = schematic | ||
return | ||
} | ||
func ComponentCapabilityDBFromCC(c ComponentCapability) (cdb ComponentCapabilityDB) { | ||
cdb.capability = c.capability | ||
cdb.TypeMeta = c.TypeMeta | ||
cdb.Spec = c.Spec | ||
cdb.Metadata, _ = json.Marshal(c.Metadata) | ||
cdb.Schematic, _ = json.Marshal(c.Schematic) | ||
return | ||
} |