@@ -7,63 +7,12 @@ import (
7
7
"github.com/intelops/compage/internal/languages"
8
8
"github.com/intelops/compage/internal/languages/templates"
9
9
log "github.com/sirupsen/logrus"
10
- "golang.org/x/exp/maps"
11
10
)
12
11
13
- // GetNodes converts nodes map to string.
14
- func GetNodes (nodes interface {}) interface {} {
15
- if nodes != nil {
16
- nodesBytes , err := json .Marshal (maps .Values (nodes .(map [string ]interface {})))
17
- if err != nil {
18
- log .Errorf ("error marshalling nodes: %v" , err )
19
- return err
20
- }
21
- return string (nodesBytes )
22
- }
23
- return ""
24
- }
25
-
26
- // GetEdges converts an edge map to string.
27
- func GetEdges (edges interface {}) interface {} {
28
- if edges != nil {
29
- edgesBytes , err := json .Marshal (maps .Values (edges .(map [string ]interface {})))
30
- if err != nil {
31
- log .Errorf ("error marshalling edges: %v" , err )
32
- return err
33
- }
34
- return string (edgesBytes )
35
- }
36
- return ""
37
- }
38
-
39
- // ConvertMap converts compageJSON structure to {edges: [], nodes:[]}
40
- func ConvertMap (x map [string ]interface {}) map [string ]interface {} {
41
- // convert key-value-based edges to edges Slice
42
- if x ["edges" ] != nil {
43
- x ["edges" ] = maps .Values (x ["edges" ].(map [string ]interface {}))
44
- }
45
- // convert key-value-based nodes to nodes Slice
46
- if x ["nodes" ] != nil {
47
- x ["nodes" ] = maps .Values (x ["nodes" ].(map [string ]interface {}))
48
- }
49
- return x
50
- }
51
-
52
12
// GetCompageJSONForGRPC converts json string to CompageJSON struct
53
13
func GetCompageJSONForGRPC (jsonString string ) (* core.CompageJSON , error ) {
54
- x := map [string ]interface {}{}
55
- if err := json .Unmarshal ([]byte (jsonString ), & x ); err != nil {
56
- log .Errorf ("error unmarshalling compageJSON: %v" , err )
57
- return nil , err
58
- }
59
- convertedX := ConvertMap (x )
60
- convertedXBytes , err1 := json .Marshal (convertedX )
61
- if err1 != nil {
62
- log .Errorf ("error marshalling compageJSON: %v" , err1 )
63
- return nil , err1
64
- }
65
14
compageJSON := & core.CompageJSON {}
66
- if err2 := json .Unmarshal (convertedXBytes , compageJSON ); err2 != nil {
15
+ if err2 := json .Unmarshal ([] byte ( jsonString ) , compageJSON ); err2 != nil {
67
16
log .Errorf ("error unmarshalling compageJSON: %v" , err2 )
68
17
return nil , err2
69
18
}
0 commit comments