s3manager-web/buckets_view.go

34 lines
753 B
Go
Raw Normal View History

2017-05-08 23:07:07 +02:00
package s3manager
2017-04-03 14:08:01 +02:00
import (
"html/template"
"net/http"
"path"
)
2017-05-08 23:07:07 +02:00
// BucketsViewHandler renders all buckets on an HTML page.
func BucketsViewHandler(s3 S3) http.Handler {
2017-04-03 14:08:01 +02:00
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 {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusInternalServerError, err)
2017-04-03 14:08:01 +02:00
return
}
buckets, err := s3.ListBuckets()
if err != nil {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusInternalServerError, err)
2017-04-03 14:08:01 +02:00
return
}
err = t.ExecuteTemplate(w, "layout", buckets)
if err != nil {
2017-04-09 16:28:57 +02:00
handleHTTPError(w, http.StatusInternalServerError, err)
2017-04-03 14:08:01 +02:00
return
}
})
}