|
|
|
@ -20,7 +20,7 @@ type Response struct { |
|
|
|
// 文件输出的结构
|
|
|
|
type FileJson struct { |
|
|
|
Fname string `json:"fname"` |
|
|
|
Dirflag int `json:isdir` |
|
|
|
Dirflag int `json:dirflag` |
|
|
|
} |
|
|
|
|
|
|
|
type FilesListJson struct { |
|
|
|
@ -73,7 +73,7 @@ func NfTest(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
data.FileName = filepath.Base(realFilePath) |
|
|
|
//data.FileName = filepath.Base(realFilePath)
|
|
|
|
flist.Flist = append(flist.Flist, FileJson{Fname: filepath.Base(realFilePath), Dirflag: 0}) |
|
|
|
} |
|
|
|
|
|
|
|
@ -83,7 +83,20 @@ func NfTest(w http.ResponseWriter, r *http.Request) { |
|
|
|
Scdir: upath, |
|
|
|
Data: flist, |
|
|
|
} |
|
|
|
// 设置跨域响应头
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "*") |
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS,PUT,DELETET") |
|
|
|
// w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Accept,Accept-Length,Accept-Encoding,X-XSRF-TOKEN,X-XSRF-TOKEN")
|
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "*") |
|
|
|
//
|
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
|
|
|
|
// 如果是OPTIONS请求,返回200 OK
|
|
|
|
if r.Method == "OPTIONS" { |
|
|
|
// fmt.Printf("options is now \n")
|
|
|
|
// w.WriteHeader(http.StatusOK)
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
json.NewEncoder(w).Encode(response) |
|
|
|
} |
|
|
|
|