From 290049bb38a1bf51d2fb746adee75d3be12d5c81 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Mon, 11 May 2020 15:14:22 +0800 Subject: [PATCH] no message --- controller/file.go | 11 ++++++++++- utils/base.go | 26 +++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/controller/file.go b/controller/file.go index 6502ea4..70be41e 100644 --- a/controller/file.go +++ b/controller/file.go @@ -4,6 +4,7 @@ import ( "background/utils" "github.com/disintegration/imaging" "github.com/gin-gonic/gin" + json "github.com/json-iterator/go" uuid "github.com/satori/go.uuid" "image" "image/color" @@ -75,11 +76,19 @@ func (this *FileController) OnUpload(c *gin.Context) { } func (this *FileController) FileList(c *gin.Context) { + var nodes utils.FileDesc path := c.Query("path") - utils.GetPathFileName("files/" + path) + utils.GetPathFileName("files\\" + path,&nodes) + log.Print(nodes) + bs,e := json.Marshal(nodes) + if nil != e{ + log.Print(e.Error()) + } + log.Print(string(bs)) c.JSON(200,map[string]interface{}{ "msg":"ok", "status":200, + "files":nodes, }) } diff --git a/utils/base.go b/utils/base.go index fa380b4..b21365f 100644 --- a/utils/base.go +++ b/utils/base.go @@ -3,6 +3,7 @@ package utils import ( "fmt" "io/ioutil" + "log" "os" "path/filepath" "strings" @@ -25,15 +26,30 @@ func GetCurrentDirectory() string { return strings.Replace(dir, "\\", "/", -1) } - -func GetPathFileName(pathname string) (error) { +type FileDesc struct { + Child []FileDesc `json:"child"` + Types int32 `json:"types"` + Name string `json:"name"` +} +func GetPathFileName(pathname string,desc *FileDesc) (error) { + log.Print("call once") + desc.Name = pathname + desc.Child = make([]FileDesc,0) + desc.Types = 1 // 1 means fileholder rd, err := ioutil.ReadDir(pathname) for _, fi := range rd { + log.Print(fi.Name()) if fi.IsDir() { - fmt.Printf("[%s]\n", pathname+"\\"+fi.Name()) - GetPathFileName(pathname + fi.Name() + "\\") + childdir := new (FileDesc) + childdir.Types = 1 + childdir.Name = fi.Name() + GetPathFileName(pathname + "\\"+ fi.Name() + "\\",childdir) + desc.Child = append(desc.Child,*childdir) } else { - fmt.Println(fi.Name()) + childdir := new (FileDesc) + childdir.Types = 0 + childdir.Name = fi.Name() + desc.Child = append(desc.Child,*childdir) } } return err