-
-
Notifications
You must be signed in to change notification settings - Fork 415
/
dot_cgo.go
37 lines (33 loc) · 801 Bytes
/
dot_cgo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build cgo
// +build cgo
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/goccy/go-graphviz"
)
func runDotToImage(outfname string, format string, dot []byte) (string, error) {
g := graphviz.New()
graph, err := graphviz.ParseBytes(dot)
if err != nil {
return "", err
}
defer func() {
if err := graph.Close(); err != nil {
log.Fatal(err)
}
g.Close()
}()
var img string
if outfname == "" {
img = filepath.Join(os.TempDir(), fmt.Sprintf("go-callvis_export.%s", format))
} else {
img = fmt.Sprintf("%s.%s", outfname, format)
}
if err := g.RenderFilename(graph, graphviz.Format(format), img); err != nil {
return "", err
}
return img, nil
}