s3manager-web/buckets-view.go

37 lines
857 B
Go
Raw Normal View History

2017-04-03 14:08:01 +02:00
package main
import (
"html/template"
"net/http"
"path"
)
// BucketsViewHandler shows all buckets
func BucketsViewHandler(s3 S3Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2017-04-07 10:07:23 +02:00
l := path.Join(tmplDirectory, "layout.html.tmpl")
p := path.Join(tmplDirectory, "buckets.html.tmpl")
2017-04-03 14:08:01 +02:00
t, err := template.ParseFiles(l, p)
if err != nil {
msg := "error parsing templates"
handleHTTPError(w, msg, err, http.StatusInternalServerError)
return
}
buckets, err := s3.ListBuckets()
if err != nil {
msg := "error listing buckets"
handleHTTPError(w, msg, err, http.StatusInternalServerError)
return
}
err = t.ExecuteTemplate(w, "layout", buckets)
if err != nil {
msg := "error executing template"
handleHTTPError(w, msg, err, http.StatusInternalServerError)
return
}
})
}