title: Get a tree like structure out of path string
body: <p>I am stuck since 2 days, as I am not to firm with pointers and recursion. I have an array of path like structures, lets say:</p>
  
  <pre><code>s:=[]string {
    "a/b/c",
    "a/b/g",
    "a/d",
  }
  </code></pre>
  
  <p>With a data structure like this:</p>
  
  <pre><code> type Node struct {
     Name     string `json:"name"`
     Children []Node `json:"children"`
  }
  </code></pre>
  
  <p>I would like to end up with something like this:</p>
  
  <pre><code>{
   "name": "a",
   "children": [
       {
        "name": "b",
        "children": [
          {
           "name": "c",
           "children": []
          },
          {
           "name": "g",
           "children": []
          }
        ]
      },
      {
       "name": "d",
       "children": []
      }
    ]
  }
  </code></pre>
  
  <p>I tried to build it with a recursion, which works kind of fine, but only for one string (e.g. "a/b/c"), as soon as I try to implement something which should add missing nodes ("g" in "a/b/g") to a tree I am stuck.</p>
  
  <p>I had something like:</p>
  
  <pre><code>func appendChild(root Node, children []string) Node {
     if len(children) == 1 {
        return Node{children[0], nil}
     } else {
        t := root
        t.Name=children[0]
        t.Children = append(t.Children, appendChild(root, children[1:]))
        return t
     }
  }
  </code></pre>
  
  <p>Could someone point me to an efficient solution?</p>