-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
dot_cgo.go
39 lines (35 loc) · 921 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
38
39
//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.Printf("error closing graph: %v", err)
}
if err := g.Close(); err != nil {
log.Printf("error closing graphviz: %v", err)
}
}()
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
}