From 94e86335b242906bb9f5178fd7dcafa15532e7a8 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sun, 10 Oct 2021 01:29:22 +0530 Subject: [PATCH] Added addChild and addChildNode functions (WIP) --- fileBrowser.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fileBrowser.go b/fileBrowser.go index edf4526..4727ccb 100644 --- a/fileBrowser.go +++ b/fileBrowser.go @@ -1,5 +1,9 @@ package main +import ( + "strings" +) + type FileNode struct{ children [] FileNode path string @@ -9,3 +13,35 @@ type FileNode struct{ func (f *FileNode) addChildren(path string){ f.children = append(f.children, FileNode{children: make([]FileNode, 0), path: path, parent: f}) } + +func (f *FileNode) addChildNode(m FileNode){ + m.parent = f + f.children = append(f.children, m) +} + +func mapGenerator(fileList [] string) map[string][]string { + var a map[string][]string = make(map[string][]string) + for i := range(fileList){ + a[strings.Split(fileList[i] , "/")[0]] = append(a[strings.Split(fileList[i] , "/")[0]], strings.Split(fileList[i] , "/")[1]) + } + return a +} + +func generateDirectoryTree(fileList [] string) *FileNode{ + var head *FileNode = new(FileNode) + for i:=0; i