Beispiel #1
0
func handlegetfiles(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	browsePath := r.Form["browsePath"][0]
	log.Println("browsePath:" + browsePath)
	fileinfos := make([]fileinfo, 0)
	filenames, _ := fileutil.GetCurrentDirFiles(browsePath)
	for _, filename := range filenames {
		fileinfos = append(fileinfos, fileinfo{Name: filename, Path: filepath.Join(browsePath, filename)})
	}
	fileinfoData, err := json.Marshal(fileinfos)
	if err != nil {
		log.Println("json init error")
	}
	// w.Header().Set("Content-Type", "application/json")
	// w.Header().Set("Cache-Control", "no-cache")
	io.WriteString(w, string(fileinfoData))
}
Beispiel #2
0
func fileHandler(w http.ResponseWriter, r *http.Request) {
	filenames, _ := fileutil.GetCurrentDirFiles(browsePath)
	// t, err := template.ParseFiles("template/html/browse.html")
	t := template.Must(template.ParseFiles("template/html/layout.html", "template/html/browse.html"))
	t.ExecuteTemplate(w, "layout", filenames)
}