Exemplo n.º 1
0
func dirListHtml(w http.ResponseWriter, r *http.Request, f fsi.File) {

	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	for {
		dirs, err := f.Readdir(100)
		if err != nil || len(dirs) == 0 {
			break
		}
		for _, d := range dirs {
			name := d.Name()

			suffix := ""
			if d.IsDir() {
				suffix = "/"
			}

			linktitle := htmlReplacer.Replace(name)
			linktitle = stringspb.Ellipsoider(linktitle, 40)
			if d.IsDir() {
				linktitle = common.Directorify(linktitle)
			}

			surl := path.Join(r.URL.Path, name) + suffix + "?fmt=html"

			oneLine := spf("<a  style='display:inline-block;min-width:600px;' href=\"%s\">%s</a>", surl, linktitle)
			// wpf(w, " %v", d.ModTime().Format("2006-01-02 15:04:05 MST"))
			oneLine += spf(" %v<br>", d.ModTime().Format(time.RFC1123Z))
			wpf(w, oneLine)
		}
	}

}
Exemplo n.º 2
0
func dirListJson(w http.ResponseWriter, r *http.Request, f fsi.File) {

	r.Header.Set("Content-Type", "application/json")

	mp := []map[string]string{}

	for {
		dirs, err := f.Readdir(100)
		if err != nil || len(dirs) == 0 {
			break
		}
		for _, d := range dirs {
			name := d.Name()
			if d.IsDir() {
				name = common.Directorify(name)
			}
			name = htmlReplacer.Replace(name)

			url := url.URL{Path: name}

			mpl := map[string]string{
				"path": url.String(),
				"mod":  d.ModTime().Format(time.RFC1123Z),
			}

			mp = append(mp, mpl)
		}
	}

	bdirListHtml, err := json.MarshalIndent(mp, "", "\t")
	if err != nil {
		wpf(w, "marshalling to []byte failed - mp was %v", mp)
		return
	}
	w.Write(bdirListHtml)

}