Browse Source

调整输出的结构

master
453530270@qq.com 2 years ago
parent
commit
0bf56f7d97
  1. 16
      fssc/internal/handler/nfhandler.go

16
fssc/internal/handler/nfhandler.go

@ -10,14 +10,15 @@ import (
// json 结构体 // json 结构体
type Response struct { type Response struct {
Status string `json:"status"` Status string `json:"status"` //状态
Data FilesListJson `json:"data"` Data FilesListJson `json:"data"` //目录下的文件
Scdir string // 扫描的目录
} }
// 文件输出的结构 // 文件输出的结构
type FileJson struct { type FileJson struct {
Fname string `json:"fname"` Fname string `json:"fname"`
Isdir bool `json:isdir` Dirflag int `json:isdir`
} }
type FilesListJson struct { type FilesListJson struct {
@ -37,16 +38,12 @@ func NfTest(w http.ResponseWriter, r *http.Request) {
} }
data := struct { data := struct {
DeviceName string
Loip string
Rundir string Rundir string
IsDir bool IsDir bool
FileName string FileName string
DownloadPath string DownloadPath string
// Files []os.DirEntry // Files []os.DirEntry
}{ }{
DeviceName: config.G.DeviceName,
Loip: config.G.LocalIP,
Rundir: config.G.FilePath, Rundir: config.G.FilePath,
DownloadPath: downloadPath, DownloadPath: downloadPath,
} }
@ -65,17 +62,18 @@ func NfTest(w http.ResponseWriter, r *http.Request) {
// data.Files = files // data.Files = files
for _, v := range files { for _, v := range files {
flist.Flist = append(flist.Flist, FileJson{Fname: v.Name(), Isdir: v.IsDir()}) flist.Flist = append(flist.Flist, FileJson{Fname: v.Name(), Dirflag: 1})
} }
} else { } else {
data.FileName = filepath.Base(realFilePath) data.FileName = filepath.Base(realFilePath)
flist.Flist = append(flist.Flist, FileJson{Fname: filepath.Base(realFilePath), Isdir: true}) flist.Flist = append(flist.Flist, FileJson{Fname: filepath.Base(realFilePath), Dirflag: 0})
} }
// respone file list // respone file list
response := Response{ response := Response{
Status: "success", Status: "success",
Scdir: realFilePath,
Data: flist, Data: flist,
} }
// //

Loading…
Cancel
Save