Categorygithub.com/rigtorp/go-graphviz
modulepackage
0.0.0-20230404030415-1d33784c44ae
Repository: https://github.com/rigtorp/go-graphviz.git
Documentation: pkg.go.dev

# README

Graphviz for Go

This package wraps Graphviz as a Go package. It doesn't rely on cgo or an external binary, instead using the wazero WebAssembly runtime to embed Graphviz.

Wazero is configured to sandbox Graphviz such that Graphviz only has access to the input and output data.

Performance

For a small Graphviz graph, go-graphviz takes about 51ms:

$ go test -test.bench .
goos: linux
goarch: amd64
pkg: github.com/rigtorp/go-graphviz
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkGraphviz-8           24          51285746 ns/op
PASS
ok      github.com/rigtorp/go-graphviz  3.057s

Building Graphviz for WASM

Download wasi-sdk and extract it somewhere.

Next build Graphviz:

mkdir build
cd build
cmake .. -DWASI_SDK_PREFIX=/path/to/wasi/sdk
ninja

Acknowledgements

I got the idea for this approach of embedding an external program in Go using WebAssembly from the blog post The carcinization of Go programs.

# Functions

Render converts input graph into output SVG figure.
RenderString converts input graph into output SVG figure.