package main import ( "flag" "fmt" "io/ioutil" "log" "antoine-roux.ml/projects/go/dijkstra/internal" stringset "antoine-roux.ml/projects/go/stringset/pkg" "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/hclsyntax" ) func main() { filename := flag.String("i", "-", "Input file use to generate graph") flag.Parse() src, err := ioutil.ReadFile(*filename) if err != nil { log.Fatalln(err) } file, diags := hclsyntax.ParseConfig(src, *filename, hcl.Pos{Line: 1, Column: 1}) if diags.HasErrors() { log.Fatalf("config parse: %s", fmt.Errorf("%w", diags)) } graph := &internal.Graph{} diags = gohcl.DecodeBody(file.Body, nil, graph) if diags.HasErrors() { log.Fatalf("config parse: %s", fmt.Errorf("%w", diags)) } graph.InitDefaultValue() /* fmt.Printf("%#v\n", *graph) for _, p := range graph.Nodes { fmt.Printf("%+v\n", p) } */ start, err := graph.GetStartingNode() fmt.Printf("%#v\n", start) ss := stringset.New(start) ss.ToString() fmt.Printf("neighbourNode of start %+v : \n", start) neig := graph.GetNeighbour(start) for _, n := range neig { fmt.Printf("%+v\n", n) g.UpdateNodeValue(start, n) } fmt.Println("level 2 neighbour") neig_level2 := graph.GetNeighbourForList(neig) for _, n := range neig_level2 { fmt.Printf("%+v\n", n) } }