From f993491633ea92c88eaf95515de0d2328e65995d Mon Sep 17 00:00:00 2001 From: Mustafa Ekicim Date: Wed, 21 Feb 2024 10:14:56 +0300 Subject: [PATCH] adding bucket name support --- internal/app/s3manager/buckets_view.go | 13 ++++++++++++- main.go | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/app/s3manager/buckets_view.go b/internal/app/s3manager/buckets_view.go index 89390253..df043e3e 100644 --- a/internal/app/s3manager/buckets_view.go +++ b/internal/app/s3manager/buckets_view.go @@ -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 @@ -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, diff --git a/main.go b/main.go index 2ffe8abd..3ae9233c 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,7 @@ type configuration struct { Timeout int32 SseType string SseKey string + bucketName string } func parseConfiguration() configuration { @@ -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, @@ -115,6 +119,7 @@ func parseConfiguration() configuration { Timeout: timeout, SseType: sseType, SseKey: sseKey, + bucketName: bucketName, } } @@ -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 {