-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move topology diff to render package.
- Loading branch information
Tom Wilkie
committed
Jun 16, 2015
1 parent
ae9ea5c
commit 4726b48
Showing
5 changed files
with
63 additions
and
53 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
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
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,41 @@ | ||
package render | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/weaveworks/scope/report" | ||
) | ||
|
||
// Diff is returned by TopoDiff. It represents the changes between two | ||
// RenderableNode maps. | ||
type Diff struct { | ||
Add []report.RenderableNode `json:"add"` | ||
Update []report.RenderableNode `json:"update"` | ||
Remove []string `json:"remove"` | ||
} | ||
|
||
// TopoDiff gives you the diff to get from A to B. | ||
func TopoDiff(a, b report.RenderableNodes) Diff { | ||
diff := Diff{} | ||
|
||
notSeen := map[string]struct{}{} | ||
for k := range a { | ||
notSeen[k] = struct{}{} | ||
} | ||
|
||
for k, node := range b { | ||
if _, ok := a[k]; !ok { | ||
diff.Add = append(diff.Add, node) | ||
} else if !reflect.DeepEqual(node, a[k]) { | ||
diff.Update = append(diff.Update, node) | ||
} | ||
delete(notSeen, k) | ||
} | ||
|
||
// leftover keys | ||
for k := range notSeen { | ||
diff.Remove = append(diff.Remove, k) | ||
} | ||
|
||
return diff | ||
} |
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
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