2017-05-08 23:07:07 +02:00
|
|
|
package s3manager
|
2017-04-03 14:08:01 +02:00
|
|
|
|
|
|
|
import (
|
2019-09-05 00:44:02 +02:00
|
|
|
"fmt"
|
2017-04-03 14:08:01 +02:00
|
|
|
"html/template"
|
2021-04-21 11:37:38 +02:00
|
|
|
"io/fs"
|
2017-04-03 14:08:01 +02:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-05-31 16:10:41 +02:00
|
|
|
// HandleBucketsView renders all buckets on an HTML page.
|
2021-04-21 11:37:38 +02:00
|
|
|
func HandleBucketsView(s3 S3, templates fs.FS) http.HandlerFunc {
|
2019-01-26 13:53:36 +01:00
|
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
2018-03-14 21:53:35 +01:00
|
|
|
buckets, err := s3.ListBuckets()
|
2017-04-03 14:08:01 +02:00
|
|
|
if err != nil {
|
2019-09-05 00:44:02 +02:00
|
|
|
handleHTTPError(w, fmt.Errorf("error listing buckets: %w", err))
|
2017-04-03 14:08:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-21 11:37:38 +02:00
|
|
|
t, err := template.ParseFS(templates, "layout.html.tmpl", "buckets.html.tmpl")
|
2017-04-03 14:08:01 +02:00
|
|
|
if err != nil {
|
2019-09-05 00:44:02 +02:00
|
|
|
handleHTTPError(w, fmt.Errorf("error parsing template files: %w", err))
|
2017-04-03 14:08:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = t.ExecuteTemplate(w, "layout", buckets)
|
|
|
|
if err != nil {
|
2019-09-05 00:44:02 +02:00
|
|
|
handleHTTPError(w, fmt.Errorf("error executing template: %w", err))
|
2017-04-03 14:08:01 +02:00
|
|
|
return
|
|
|
|
}
|
2018-05-31 16:10:41 +02:00
|
|
|
}
|
2017-04-03 14:08:01 +02:00
|
|
|
}
|