forked from grafana/tanka
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
112 additions
and
28 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
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
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,34 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
// ShowJSON marshals the state into plain JSON | ||
func ShowJSON(state interface{}) (string, error) { | ||
out, err := json.MarshalIndent(state, "", " ") | ||
return string(out), err | ||
} | ||
|
||
// ShowYAML marshals the state into a single YAML document. | ||
func ShowYAML(state interface{}) (string, error) { | ||
out, err := yaml.Marshal(state) | ||
return string(out), err | ||
} | ||
|
||
// ShowYAMLDocs the state into multiple yaml documents | ||
func ShowYAMLDocs(state []map[string]interface{}) (string, error) { | ||
buf := bytes.Buffer{} | ||
enc := yaml.NewEncoder(&buf) | ||
|
||
for _, d := range state { | ||
if err := enc.Encode(d); err != nil { | ||
return "", err | ||
} | ||
} | ||
|
||
return buf.String(), nil | ||
} |