INNER CODE UNIT · Go
WriteGraphJSON
pcasteran/terraform-graph-beautifier · cytoscape/writer.go:23
func WriteGraphJSON(writer io.Writer, graph *tfgraph.Graph, options *RenderingOptions) {
// Get the graph elements.
graphElements := getGraphElements(graph, options)
// Encode the result to JSON.
enc := json.NewEncoder(writer)
if err := enc.Encode(&graphElements); err != nil {
log.Fatal().Err(err).Msg("Cannot encode Cytoscape.js graph to JSON")
}
}
// WriteGraphHTML writes the specified Terraform graph to an HTML file using the given template.
func WriteGraphHTML(writer io.Writer, graph *tfgraph.Graph, options *RenderingOptions) {
// Get the graph elements JSON.
var buf bytes.Buffer
graphWriter := bufio.NewWriter(&buf)
WriteGraphJSON(graphWriter, graph, options)
graphWriter.Flush()