-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.go
73 lines (57 loc) · 1.56 KB
/
link.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2021 The Tiyo authors
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package pipeline
// Link : Common structure between element link types
type Link struct {
// JointJS ID of the current link
ID string
// Type of link being drawn
Type string
// JointJS Source element ID of the link
Source string
// JointJS Destination element ID of the link
Target string
}
// LinkInterface : Common methods to read data from a link type
type LinkInterface interface {
// GetType : Get the type of link
GetType() string
// GetLink : Get the common link details
GetLink() Link
}
// NewLink : Create a new Link object
func NewLink(cell map[string]interface{}) LinkInterface {
link := GetLink(cell)
if link.Type == "tcp" || link.Type == "udp" {
return NewPortLink(cell)
}
return NewPathLink(cell)
}
// GetLink : Unpack a link out of map[string]interface
func GetLink(cell map[string]interface{}) Link {
link := Link{
ID: "",
Type: "",
Source: "",
Target: "",
}
if cell["id"] != nil {
link.ID = cell["id"].(string)
}
attrib := cell["attributes"].(map[string]interface{})
source := cell["source"].(map[string]interface{})
target := cell["target"].(map[string]interface{})
if attrib["type"] != nil {
link.Type = attrib["type"].(string)
}
if source["id"] != nil {
link.Source = source["id"].(string)
}
if target["id"] != nil {
link.Target = target["id"].(string)
}
return link
}