graph

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graph provides functionality to build a graph of connected nodes with a cfn.Template

Example (Get)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	fmt.Println(g.Get(graph.Node{"Parameters", "Name"}))
	fmt.Println(g.Get(graph.Node{"Resources", "Bucket"}))
	fmt.Println(g.Get(graph.Node{"Outputs", "BucketName"}))
}
Output:
[]
[Parameters/AWS::AccountId Parameters/Name Resources/LogBucket]
[Resources/Bucket]
Example (GetReverse)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	fmt.Println(g.GetReverse(graph.Node{"Parameters", "Name"}))
	fmt.Println(g.GetReverse(graph.Node{"Resources", "Bucket"}))
	fmt.Println(g.GetReverse(graph.Node{"Outputs", "BucketName"}))
}
Output:
[Resources/Bucket]
[Outputs/BucketArn Outputs/BucketName]
[]
Example (Nodes)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	for _, node := range g.Nodes() {
		fmt.Println(node)
	}
}
Output:
Parameters/AWS::AccountId
Parameters/Name
Resources/LogBucket
Resources/Bucket
Outputs/BucketArn
Outputs/BucketName

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph represents a directed, acyclic graph with ordered nodes

func Empty added in v1.7.0

func Empty() Graph

Empty returns a new, empty graph

func New

func New(t cft.Template) Graph

New returns a Graph representing the connections between elements in the provided template. The type of each item in the graph is Node

func (Graph) Get

func (g Graph) Get(item Node) []Node

Get returns all nodes that are connected to the item that you pass in.

func (Graph) GetReverse

func (g Graph) GetReverse(item Node) []Node

GetReverse returns all nodes that connect to the item that you pass in.

func (g *Graph) Link(item Node, links ...Node)

link creates a connection between two nodes in the graph

func (Graph) Nodes

func (g Graph) Nodes() []Node

Nodes returns all nodes of the graph, in order of their dependencies. Nodes with the fewest dependencies are at the beginning of the slice.

func (*Graph) String

func (g *Graph) String() string

type Node

type Node struct {
	// Type is the name of the top-level part of a template
	// that contains this Node (e.g. Resources, Parameters)
	Type string

	// Name is the name of the Node
	Name string
}

Node represents a top-level entry in a CloudFormation template for example a resource, parameter, or output

func (Node) String

func (n Node) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL