Exemplo n.º 1
0
// Render - Method for rendering DOT from base64 to image
func (dot *DotController) Render(res http.ResponseWriter, params martini.Params) {
	format := params["format"]
	data := params["data"]

	err := dot.checkFormat(format)
	if err != nil {
		log.Println(err)
		res.WriteHeader(http.StatusBadRequest)
		res.Write([]byte(fmt.Sprintln(err)))
		return
	}

	graph, err := base64.StdEncoding.DecodeString(data)
	if err != nil {
		log.Println(err)
		res.WriteHeader(http.StatusBadRequest)
		return
	}

	result, err := godotviz.DotRender(graph, format)
	if err != nil {
		log.Println(err)
		res.WriteHeader(http.StatusInternalServerError)
		return
	}

	res.Header().Set("Content-Type", "image/"+format)
	res.Write(result)

}
Exemplo n.º 2
0
// main - implements simple processing DOT language from stdin to stdout
// Example:
// echo 'graph {a -- b a -- b  b -- c }' | go run dotpipeviz.go png > ~/graph.png
func main() {
	fileFormat := os.Args[1]

	data, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}

	result, err := godotviz.DotRender(data, fileFormat)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout.Write(result)
}