Skip to content
Snippets Groups Projects
Commit f4e69636 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

fixed memory violation. stray nil dirs around tho

parent 00357cd1
No related branches found
No related tags found
3 merge requests!93Path traversal demo,!91"Overhaul Architecture",!90Develop
Pipeline #60728 passed with warnings
...@@ -11,6 +11,22 @@ type PathElement struct { ...@@ -11,6 +11,22 @@ type PathElement struct {
Name string Name string
} }
func (p *PathElement)Print() {
printPE(0, p)
}
func printPE(indent int, pe *PathElement) {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Println(pe.Name)
if len(pe.Children) > 0 {
for _,p := range pe.Children {
printPE(indent+1, p)
}
}
}
func main() { func main() {
tree := schema.SchemaTree tree := schema.SchemaTree
paths := make(map[string]*PathElement) paths := make(map[string]*PathElement)
...@@ -18,11 +34,12 @@ func main() { ...@@ -18,11 +34,12 @@ func main() {
for k,v := range tree { for k,v := range tree {
if v.Parent != nil { if v.Parent != nil {
if v.Parent.Name == "device" { if v.Parent.Name == "device" {
paths[k] = processEntry(v) pathElement := processEntry(v)
pathElement.Print()
paths[k] = pathElement
} }
} }
} }
fmt.Println("stop")
} }
func processEntry(e *yang.Entry) *PathElement { func processEntry(e *yang.Entry) *PathElement {
...@@ -31,9 +48,10 @@ func processEntry(e *yang.Entry) *PathElement { ...@@ -31,9 +48,10 @@ func processEntry(e *yang.Entry) *PathElement {
Children: make([]*PathElement, len(e.Dir)), Children: make([]*PathElement, len(e.Dir)),
Name: e.Name, Name: e.Name,
} }
i := 0
for _,v := range e.Dir { for _,v := range e.Dir {
child := processEntry(v) elem.Children[i] = processEntry(v)
elem.Children = append(elem.Children, child) i++
} }
return elem return elem
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment