老许的第5章 网络编程 146 页
listHtml += "<li><a href=\"/view?id=" + imgid + "\">imgid</a></li>"
报错啊!
invalid operation: "<li><a href=\"/view?id=" + imgid (mismatched types string and func() string)
你确定没抄错?
imgid := fileInfo.Name
这里应该是:fileInfo.Name()
os.FileInfo 接口的Name()方法
#5
更多评论
连个图片也不支持啊,http://www.freeimagehosting.net/9ygno.png
package main
func listHandler(w http.ResponseWriter, r *http.Request) {
fileInfoArr, err := ioutil.ReadDir("./uploads")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var listHtml string
for _, fileInfo := range fileInfoArr {
imgid := fileInfo.Name
listHtml += "<li><a href=\"/view?id=" + imgid + "\">imgid</a></li>"
}
io.WriteString(w, "<ol>"+listHtml+"</ol>")
}
#4