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, and More.

Visual representations are an essential aspect of conveying complex ideas and systems in a more understandable and approachable way. In the world of software development, creating diagrams and visual representations of systems, networks, and architectures is an essential part of the process. These visual aids help software developers and engineers communicate complex ideas and concepts effectively. Go-Diagrams, a powerful Go library, simplifies the creation of diagrams, making it easier than ever to visualize your projects.

Go-Diagrams is an open source Go library that is developed by Blushft. The library is very easy to handle and enables Software Developers to create diagrams programmatically. It is designed to be simple to use, yet flexible and powerful enough to create a wide variety of diagrams, including network diagrams, flowcharts, infrastructure diagrams, and more. Whether you are building a visualization tool, documenting your code, or generating diagrams for any other purpose, go-diagrams can be a valuable addition to your toolkit.

Go-Diagrams is a valuable addition to the Go ecosystem, simplifying the creation of diagrams for software projects. Its ease of use, modularity, and extensibility make it a powerful tool for software developers and engineers looking to communicate their ideas effectively. Whether you're designing a cloud-based system, documenting your micro-services architecture, or simply sketching out ideas, Go-Diagrams provides a straightforward and efficient way to bring your diagrams to life. Give it a try in your next project, and you'll discover how it can transform the way you visualize and share 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