Last active
April 13, 2020 18:17
-
-
Save alextanhongpin/a90e68fe7842c5036319f90083bac7b2 to your computer and use it in GitHub Desktop.
Sample golang code that pipes the dynamic .dot file data to external graphviz process to write the .png file
This file contains hidden or 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
// -- IMPORTSS NOT SHOWN | |
path, _ := exec.LookPath("dot") | |
cmd := exec.Command(path, fmt.Sprintf("-T%s", "png")) | |
stdin, err := cmd.StdinPipe() | |
if err != nil { | |
log.Fatal(err) | |
} | |
go func() { | |
defer stdin.Close() | |
// Writes the data to stdin. | |
Render(data, stdin) | |
}() | |
writeCmd, err := cmd.Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
mode := int(0644) | |
ioutil.WriteFile("out.png", writeCmd, os.FileMode(mode)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment