1. Products
  2.   Diagram
  3.   GO
  4.   Go-Diagrams
 
  

Free Go Library to Read & Write Wide Variety of Diagrams

A Powerful Open Source Go Diagraming Library to Create a Wide Variety of Diagrams, Including Network Diagrams, Flowcharts, Infrastructure Diagrams & more and Export Diagrams to SVG/PNG.

What is Go-Diagrams Library?

When you’re dealing with complex ideas and systems in software development, using visuals is key to making things easier to grasp. Creating diagrams and visual representations of systems, networks, and architectures is crucial in this field. These visual tools really come in handy for software developers and engineers to share their ideas and concepts effectively. Go-Diagrams, a handy Go library, makes it super easy to create diagrams, simplifying the whole process for you. Whether you’re working on a visualization tool, documenting your code, or creating diagrams for any other reason, go-diagrams can be a valuable tool in your arsenal. Blushft has created Go-Diagrams, an open-source Go library that makes life easier for Software Developers. With this library, you can create diagrams programmatically without any hassle.

Go-Diagrams is a great tool that enhances the Go ecosystem by making it easier to create diagrams for your software projects. It’s user-friendly, flexible, and customizable, which makes it a valuable asset for software developers and engineers who want to convey their concepts clearly. It is crafted to be user-friendly and versatile, giving you the ability to design various diagrams like network diagrams, flowcharts, infrastructure diagrams, and more. Whether you’re working on a cloud-based system, outlining your micro-services architecture, or just brainstorming, Go-Diagrams offers a simple and effective method to visualize your diagrams effectively. Try using it in your next project, and you’ll see how it can change the way you imagine and communicate your software architecture and design.

Previous Next

Getting Started with Go-Diagrams

The recommend way to install Go-Diagrams is using GitHub. Please use the following command for a smooth installation.

Install Go-Diagrams Library via GitHub

go get github.com/blushft/go-diagrams
You can also download it directly from GibHub.

Create a Diagram using Go Library

The open source Go-Diagrams library makes it easy for software developer to create a new diagram from the scratch inside Go applications. The library offers a user-friendly API that abstracts away much of the complexity of diagram creation. It uses a simple and intuitive syntax to define your diagram elements, making it accessible to both beginners and experienced developers. Below is a simple example that shows how software developers can create a basic diagram with just a couple of lines of Go commands.

How to Create a Basic Diagram using Go-Diagrams Library?

package main

import (
	"fmt"

	"github.com/blushft/go-diagrams/v2/diagram"
)

func main() {
	// Create a new diagram
	d, err := diagram.New(diagram.Label("My Diagram"))
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	// Create a node and add it to the diagram
	node := d.NewNode("Node 1")

	// Render the diagram as SVG
	err = d.Render()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
}

Declarative Syntax Support via Go API

One of the standout features of Do-Diagrams library is its declarative syntax. Software developers can define their diagrams using a clear and concise code that resembles a DSL (domain-specific language). This makes it easy to create and modify diagrams, even for those who are not graphic design experts. Moreover, the library is extensible, allowing users to create custom components and styles to suit their specific needs. Users can customize the appearance and behavior of their diagrams to align with project's requirements.

Export Diagrams to SVG/PNG via Go

The open source Go-Diagrams library allows software professionals to load and export various types of diagrams to popular image file formats inside Go applications. The library supports the generation of diagrams in both SVG and PNG formats, making it versatile for various use cases. Users can easily export diagrams for web applications, documentation, or presentations without any external dependencies. The following Example demonstrates how software developers can generate a diagram and exports it in both SVG and PNG formats inside Go applications.

How to Export a Diagram in SVG and PNG formats inside Go applications

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/blushft/go-diagrams/v2/diagram"
)

func main() {
	// Create a new diagram
	d, err := diagram.New(diagram.Label("My Diagram"))
	if err != nil {
		log.Fatalf("Error creating diagram: %v", err)
	}

	// Create a node and add it to the diagram
	node := d.NewNode("Node 1")

	// Export the diagram as SVG
	svgFilePath := "diagram.svg"
	err = d.RenderToFile(svgFilePath)
	if err != nil {
		log.Fatalf("Error rendering SVG: %v", err)
	}
	fmt.Printf("Diagram saved as %s\n", svgFilePath)

	// Export the diagram as PNG
	pngFilePath := "diagram.png"
	err = d.RenderToFile(pngFilePath)
	if err != nil {
		log.Fatalf("Error rendering PNG: %v", err)
	}
	fmt.Printf("Diagram saved as %s\n", pngFilePath)
}

 English