package main
import (
"encoding/json"
"log"
"fmt"
"github.com/lempiy/dgraph"
"github.com/lempiy/dgraph/core"
)
const data = `[
{
"id": "Client",
"next": ["Route53"]
},
{
"id": "Route53",
"next": ["ELB", "CloudFront"]
},
{
"id": "CloudFront",
"next": ["S3"]
},
{
"id": "S3",
"next": []
},
{
"id": "ELB",
"next": ["WebServer1", "WebServer2", "WebServer3", "WebServer4"]
},
{
"id": "WebServer1",
"next": ["LB1"]
},
{
"id": "WebServer2",
"next": ["LB1"]
},
{
"id": "WebServer3",
"next": ["LB2"]
},
{
"id": "WebServer4",
"next": ["LB2"]
},
{
"id": "LB1",
"next": ["AppServer1", "AppServer2"]
},
{
"id": "LB2",
"next": ["AppServer3", "AppServer4"]
},
{
"id": "AppServer1",
"next": ["DBMaster", "DBReplica1"]
},
{
"id": "AppServer2",
"next": ["DBMaster", "DBReplica1"]
},
{
"id": "AppServer3",
"next": ["DBMaster", "DBReplica2"]
},
{
"id": "AppServer4",
"next": ["DBMaster", "DBReplica2"]
},
{
"id": "DBReplica1",
"next": ["DBMaster"]
},
{
"id": "DBReplica2",
"next": ["DBMaster"]
},
{
"id": "DBMaster",
"next": []
}
]`
func main() {
var list []core.NodeInput
err := json.Unmarshal([]byte(data), &list)
if err != nil {
log.Fatal(err)
return
}
canvas, err := dgraph.DrawGraph(list)
if err != nil {
log.Fatal(err)
return
}
fmt.Printf("%s\n", canvas)
}
Output:
βββββββββββ βββββββββββ βββββββ βββββββββββββββ βββββββ βββββββββββββββ βββββββββββββ
β Client βββββ€ Route53 βββββββββ€ ELB βββββββββ€ WebServer1 βββββ€ LB1 βββββ€ AppServer1 βββββββββββββββββββββββ€ DBMaster β
βββββββββββ ββββββ¬βββββ ββββ¬βββ βββββββββββββββ ββββ¬βββ ββββββββ¬βββββββ βββββββ¬ββββββ
β β β β β
β β β β β
β β β β β
β β βββββββββββββββ β β βββββββββββββββ β
β ββββββββββββ€ WebServer2 ββββββββ€ ββββββββββββ€ DBReplica1 βββββββββββ€
β β βββββββββββββββ β ββββββββ¬βββββββ β
β β β β β
β β β β β
β β β β β
β β β βββββββββββββββ β β
β β ββββββββ€ AppServer2 ββββββββββββΌβββββββββββββββββ€
β β ββββββββ¬βββββββ β β
β β β β β
β β β β β
β β β β β
β β β β β
β β βββββββββββββββββββ β
β β β
β β β
β β β
β β β
β β βββββββββββββββ βββββββ βββββββββββββββ β
β ββββββββββββ€ WebServer3 βββββ€ LB2 βββββ€ AppServer3 βββββββββββββββββββββββββββββ€
β β βββββββββββββββ ββββ¬βββ ββββββββ¬βββββββ β
β β β β β
β β β β β
β β β β β
β β βββββββββββββββ β β βββββββββββββββ β
β ββββββββββββ€ WebServer4 ββββββββ€ ββββββββββββ€ DBReplica2 βββββββββββ€
β βββββββββββββββ β ββββββββ¬βββββββ β
β β β β
β β β β
β β β β
β βββββββββββββββ βββββββ β βββββββββββββββ β β
ββββββββββ€ CloudFront βββββββββ€ S3 β ββββββββ€ AppServer4 ββββββββββββΌβββββββββββββββββ
βββββββββββββββ βββββββ ββββββββ¬βββββββ β
β β
β β
β β
β β
βββββββββββββββββββ
If you need to render your graph in other format. You can use core
package to get low level core.Matrix
struct.