代码拉取完成,页面将自动刷新
package browser
import (
"io"
"net/http"
"strings"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
"github.com/julienschmidt/httprouter"
)
type browseModel struct {
Path string
Bucket string
Subfolders []string
Files []string
}
func handlePath(res http.ResponseWriter, req *http.Request, p httprouter.Params) {
ctx := appengine.NewContext(req)
s := getSession(ctx, req)
if s.Bucket == "" {
http.Redirect(res, req, "/", http.StatusSeeOther)
return
}
cctx, err := getCloudContext(ctx, s.Credentials)
if err != nil {
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
path := p.ByName("path")
if !strings.HasSuffix(path, delimiter) {
res.Header().Set("Content-Disposition", "attachment")
f, err := getFile(cctx, s.Bucket, path[1:])
if err != nil {
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
defer f.Close()
io.Copy(res, f)
} else {
files, subfolders, err := listFiles(cctx, s.Bucket, path[1:])
if err != nil {
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
data := browseModel{
Path: path,
Bucket: s.Bucket,
Subfolders: subfolders,
Files: files,
}
err = tpl.ExecuteTemplate(res, "browse", data)
if err != nil {
http.Error(res, "Server Error", http.StatusInternalServerError)
log.Errorf(ctx, err.Error())
return
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。