Browse Source

修复json输出的类型

master
453530270@qq.com 2 years ago
parent
commit
25cde52fae
  1. 17
      fssc/internal/handler/nfhandler.go

17
fssc/internal/handler/nfhandler.go

@ -2,7 +2,6 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"fmt"
"fssc/config" "fssc/config"
"net/http" "net/http"
"os" "os"
@ -12,7 +11,7 @@ import (
// json 结构体 // json 结构体
type Response struct { type Response struct {
Status string `json:"status"` Status string `json:"status"`
Message string `json:"data"` Data FilesListJson `json:"data"`
} }
// 文件输出的结构 // 文件输出的结构
@ -52,10 +51,6 @@ func NfTest(w http.ResponseWriter, r *http.Request) {
DownloadPath: downloadPath, DownloadPath: downloadPath,
} }
// 文件灌入数组中
// var gmap map[string]interface{}
// gmap = make(map[string]interface{})
// list json // list json
var flist FilesListJson var flist FilesListJson
@ -70,8 +65,6 @@ func NfTest(w http.ResponseWriter, r *http.Request) {
// data.Files = files // data.Files = files
for _, v := range files { for _, v := range files {
// gmap[k]["filename"] = v.Name()
// gmap[k]["isdir"] = v.IsDir()
flist.Flist = append(flist.Flist, FileJson{Fname: v.Name(), Isdir: v.IsDir()}) flist.Flist = append(flist.Flist, FileJson{Fname: v.Name(), Isdir: v.IsDir()})
} }
@ -80,16 +73,10 @@ func NfTest(w http.ResponseWriter, r *http.Request) {
flist.Flist = append(flist.Flist, FileJson{Fname: filepath.Base(realFilePath), Isdir: true}) flist.Flist = append(flist.Flist, FileJson{Fname: filepath.Base(realFilePath), Isdir: true})
} }
// 绑定到jfile
jdata, err := json.Marshal(flist)
if err != nil {
fmt.Printf("gmap has error:%v\n", err)
}
// respone file list // respone file list
response := Response{ response := Response{
Status: "success", Status: "success",
Message: string(jdata), Data: flist,
} }
// //
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")

Loading…
Cancel
Save