-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3b2b57
commit 5b8ac7d
Showing
3 changed files
with
39 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package goformation | ||
package cloudformation | ||
|
||
import "time" | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package goformation | ||
package cloudformation | ||
|
||
import ( | ||
"reflect" | ||
|
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,37 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// ByJSONLength implements the sort interface and enables sorting by JSON length | ||
type ByJSONLength []interface{} | ||
|
||
func (s ByJSONLength) Len() int { | ||
return len(s) | ||
} | ||
|
||
func (s ByJSONLength) Swap(i, j int) { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
|
||
func (s ByJSONLength) Less(i, j int) bool { | ||
// Nil is always at the end | ||
if s[i] == nil { | ||
return false | ||
} | ||
if s[j] == nil { | ||
return true | ||
} | ||
jsoni, _ := json.Marshal(s[i]) | ||
jsonj, _ := json.Marshal(s[j]) | ||
|
||
if jsoni == nil { | ||
return false | ||
} | ||
if jsonj == nil { | ||
return true | ||
} | ||
|
||
return len(jsoni) > len(jsonj) | ||
} |