mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
update comments
This commit is contained in:
parent
e66225b8e3
commit
1310fcfc0b
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CompareJSONDecode decodes a JSON string into a provided interface and then back to a json string. If the output json string does not match the compact version of the input string a error is returned
|
||||||
func CompareJSONDecode(j string, v interface{}) error {
|
func CompareJSONDecode(j string, v interface{}) error {
|
||||||
bytes, errCompact := CompactJSON(j)
|
bytes, errCompact := CompactJSON(j)
|
||||||
if errCompact != nil {
|
if errCompact != nil {
|
||||||
@ -26,6 +27,7 @@ func CompareJSONDecode(j string, v interface{}) error {
|
|||||||
return DiffStrings(old, new)
|
return DiffStrings(old, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompareStructToJSON compares Marshaled interface to a JSON string and returns an error if they do not match
|
||||||
func CompareStructToJSON(v interface{}, j string) error {
|
func CompareStructToJSON(v interface{}, j string) error {
|
||||||
// Remove all extra spaces from json string
|
// Remove all extra spaces from json string
|
||||||
bytes, errCompact := CompactJSON(j)
|
bytes, errCompact := CompactJSON(j)
|
||||||
@ -43,6 +45,7 @@ func CompareStructToJSON(v interface{}, j string) error {
|
|||||||
return DiffStrings(old, new)
|
return DiffStrings(old, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffStrings prints a nice compare between strings. Error is returned if strings are not equal
|
||||||
func DiffStrings(s1, s2 string) error {
|
func DiffStrings(s1, s2 string) error {
|
||||||
if s1 != s2 {
|
if s1 != s2 {
|
||||||
fmt.Println("String do not match!")
|
fmt.Println("String do not match!")
|
||||||
@ -62,6 +65,7 @@ func DiffStrings(s1, s2 string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompactJSON removes all whitespaces between json keys and values that is not required
|
||||||
func CompactJSON(j string) ([]byte, error) {
|
func CompactJSON(j string) ([]byte, error) {
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
@ -74,3 +78,5 @@ func CompactJSON(j string) ([]byte, error) {
|
|||||||
|
|
||||||
return bytes, nil
|
return bytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BridgeFromEnv creates a bridge from the config data stored in env. This is primarily designed for automated tests
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user