Go package providing checks for acyclic structures to ensure they can be marshaled to JSON and other forms requiring an acyclic graph
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
check.go
check_test.go
doc.go
print.go
print_test.go

README.md

acyclic

GoDoc

package acyclic provides the ability to quickly check for cycles within a data structure before attempting to marshal to JSON or similar formats.

A set of functions are also provided to print these structures in a safe manner that won't result in a stack overflow, pruning branches containing cycles and clearly marking where they occurred.

Cycles are detected using depth first search.

Usage example

import "github.com/theothertomelliott/acyclic"

func main() {
    // Create a pointer to a struct
    value := &struct {
        A string
        B interface{}
    }{
        A: "a string",
    }

    // Add a cycle
    value.B = value

    err := acyclic.Check(value)
    if err != nil {
        fmt.Println("Cycle found")
    } else {
        fmt.Println("No cycle")
    }
}