s3manager-web/internal/app/s3manager/buckets_view.go
Sergey Shevchenko c077332721 Refactoring:
- Replaced router by gorrila/mux
- Used viper for environment variables instead of os
- Added option to forbid object deletion
- Added option to list bucket recursively
- Added option to not add donwload headers in getObject
- Added ability to download nested objects
- Object donwloading will open in a new tab

Signed-off-by: Sergey Shevchenko <sergeyshevchdevelop@gmail.com>
2022-03-28 11:37:49 +02:00

42 lines
953 B
Go

package s3manager
import (
"fmt"
"html/template"
"io/fs"
"net/http"
"github.com/minio/minio-go/v7"
)
// HandleBucketsView renders all buckets on an HTML page.
func HandleBucketsView(s3 S3, templates fs.FS, allowDelete bool) http.HandlerFunc {
type pageData struct {
Buckets []minio.BucketInfo
AllowDelete bool
}
return func(w http.ResponseWriter, r *http.Request) {
buckets, err := s3.ListBuckets(r.Context())
if err != nil {
handleHTTPError(w, fmt.Errorf("error listing buckets: %w", err))
return
}
data := pageData{
Buckets: buckets,
AllowDelete: allowDelete,
}
t, err := template.ParseFS(templates, "layout.html.tmpl", "buckets.html.tmpl")
if err != nil {
handleHTTPError(w, fmt.Errorf("error parsing template files: %w", err))
return
}
err = t.ExecuteTemplate(w, "layout", data)
if err != nil {
handleHTTPError(w, fmt.Errorf("error executing template: %w", err))
return
}
}
}