Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion internal/app/s3manager/buckets_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// HandleBucketsView renders all buckets on an HTML page.
func HandleBucketsView(s3 S3, templates fs.FS, allowDelete bool) http.HandlerFunc {
func HandleBucketsView(s3 S3, templates fs.FS, allowDelete bool, bucketName string) http.HandlerFunc {
type pageData struct {
Buckets []minio.BucketInfo
AllowDelete bool
Expand All @@ -23,6 +23,17 @@ func HandleBucketsView(s3 S3, templates fs.FS, allowDelete bool) http.HandlerFun
return
}

var filteredBuckets []minio.BucketInfo
if bucketName != "" {
for _, bucket := range buckets {
if bucket.Name == bucketName {
filteredBuckets = append(filteredBuckets, bucket)
break // Eşleşen ilk bucket bulunduğunda döngüden çık
}
}
buckets = filteredBuckets
}

data := pageData{
Buckets: buckets,
AllowDelete: allowDelete,
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type configuration struct {
Timeout int32
SseType string
SseKey string
bucketName string
}

func parseConfiguration() configuration {
Expand Down Expand Up @@ -98,6 +99,9 @@ func parseConfiguration() configuration {
viper.SetDefault("SSE_KEY", "")
sseKey := viper.GetString("SSE_KEY")

viper.SetDefault("BUCKET_NAME", "")
bucketName := viper.GetString("BUCKET_NAME")

return configuration{
Endpoint: endpoint,
UseIam: useIam,
Expand All @@ -115,6 +119,7 @@ func parseConfiguration() configuration {
Timeout: timeout,
SseType: sseType,
SseKey: sseKey,
bucketName: bucketName,
}
}

Expand Down Expand Up @@ -175,7 +180,7 @@ func main() {
r := mux.NewRouter()
r.Handle("/", http.RedirectHandler("/buckets", http.StatusPermanentRedirect)).Methods(http.MethodGet)
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.FS(statics)))).Methods(http.MethodGet)
r.Handle("/buckets", s3manager.HandleBucketsView(s3, templates, configuration.AllowDelete)).Methods(http.MethodGet)
r.Handle("/buckets", s3manager.HandleBucketsView(s3, templates, configuration.AllowDelete,configuration.bucketName)).Methods(http.MethodGet)
r.PathPrefix("/buckets/").Handler(s3manager.HandleBucketView(s3, templates, configuration.AllowDelete, configuration.ListRecursive)).Methods(http.MethodGet)
r.Handle("/api/buckets", s3manager.HandleCreateBucket(s3)).Methods(http.MethodPost)
if configuration.AllowDelete {
Expand Down