Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <[email protected]>
  • Loading branch information
ondrajz committed Jan 4, 2025
1 parent ec4f660 commit 642190a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ func runDotToImageCallSystemGraphviz(outfname string, format string, dot []byte)
dotSystemBinary = dot
}

var img string
var path string
if outfname == "" {
img = filepath.Join(os.TempDir(), fmt.Sprintf("go-callvis_export.%s", format))
path = filepath.Join(os.TempDir(), fmt.Sprintf("go-callvis_export.%s", format))
} else {
img = fmt.Sprintf("%s.%s", outfname, format)
path = fmt.Sprintf("%s.%s", outfname, format)
}
cmd := exec.Command(dotSystemBinary, fmt.Sprintf("-T%s", format), "-o", img)
cmd := exec.Command(dotSystemBinary, fmt.Sprintf("-T%s", format), "-o", path)
cmd.Stdin = bytes.NewReader(dot)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("command '%v': %v\n%v", cmd, err, stderr.String())
}
return img, nil
return path, nil
}
11 changes: 5 additions & 6 deletions dot_cgo.go → graphviz_cgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cgo
// +build cgo

package main

Expand All @@ -26,14 +25,14 @@ func runDotToImage(outfname string, format string, dot []byte) (string, error) {
log.Printf("error closing graphviz: %v", err)
}
}()
var img string
var path string
if outfname == "" {
img = filepath.Join(os.TempDir(), fmt.Sprintf("go-callvis_export.%s", format))
path = filepath.Join(os.TempDir(), fmt.Sprintf("go-callvis_export.%s", format))
} else {
img = fmt.Sprintf("%s.%s", outfname, format)
path = fmt.Sprintf("%s.%s", outfname, format)
}
if err := g.RenderFilename(graph, graphviz.Format(format), img); err != nil {
if err := g.RenderFilename(graph, graphviz.Format(format), path); err != nil {
return "", err
}
return img, nil
return path, nil
}
1 change: 0 additions & 1 deletion dot_nocgo.go → graphviz_nocgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !cgo
// +build !cgo

package main

Expand Down

0 comments on commit 642190a

Please sign in to comment.