-
Notifications
You must be signed in to change notification settings - Fork 2
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
7072478
commit 8d2cb8a
Showing
5 changed files
with
279 additions
and
134 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package librato | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// Encodes a hash into a JSON string | ||
func attributesFlatten(attrs map[string]string) (string, error) { | ||
byteArray, err := json.Marshal(attrs) | ||
if err != nil { | ||
return "", fmt.Errorf("Error encoding to JSON: %s", err) | ||
} | ||
|
||
return string(byteArray), nil | ||
} | ||
|
||
// Takes JSON in a string & decodes into a hash | ||
func attributesExpand(raw string) (map[string]string, error) { | ||
attrs := make(map[string]string) | ||
err := json.Unmarshal([]byte(raw), &attrs) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error decoding JSON: %s", err) | ||
} | ||
|
||
return attrs, err | ||
} | ||
|
||
func normalizeJSON(jsonString interface{}) string { | ||
if jsonString == nil || jsonString == "" { | ||
return "" | ||
} | ||
var j interface{} | ||
err := json.Unmarshal([]byte(jsonString.(string)), &j) | ||
if err != nil { | ||
return fmt.Sprintf("Error parsing JSON: %s", err) | ||
} | ||
b, _ := json.Marshal(j) | ||
return string(b[:]) | ||
} |
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,12 @@ | ||
package librato | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func sleep(t *testing.T, amount time.Duration) func() { | ||
return func() { | ||
time.Sleep(amount * time.Second) | ||
} | ||
} |
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
Oops, something went wrong.