From 8713253df0e837bf615ee666ee56807921e25f8f Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 7 Dec 2021 18:26:16 +0100 Subject: [PATCH] Fix bug --- main.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index f2aabfc..9ae6c5e 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strings" "net/http" "crypto/tls" + "strconv" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -22,12 +23,21 @@ import ( func main() { - mc, err := minio.New(os.Getenv("ENDPOINT"), &minio.Options{ + _, isSSL := os.LookupEnv("SSL"); + opts := minio.Options { Creds: credentials.NewStaticV4(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), ""), - Secure: true, - Region: os.Getenv("REGION"), - Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, - }) + Secure: isSSL, + } + + if region, ok := os.LookupEnv("REGION"); ok { + opts.Region = region + } + + if _, ok := os.LookupEnv("SSL_INSECURE"); ok { + opts.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} + } + + mc, err := minio.New(os.Getenv("ENDPOINT"), &opts) if err != nil { log.Fatal("failed connect", err) @@ -46,9 +56,10 @@ func main() { } for i := 0; i < 100; i++ { - content := string(i) + " hello world " + string(i) + istr := strconv.Itoa(i) + content := istr + " hello world " + istr start := time.Now() - _, err := mc.PutObject(context.Background(), "bench1", "element"+string(i), strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType:"application/octet-stream"}) + _, err := mc.PutObject(context.Background(), "bench1", "element"+istr, strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType:"application/octet-stream"}) elapsed := time.Since(start) if err != nil { log.Fatal("failed putObject: ",err) @@ -76,8 +87,9 @@ func main() { } for i := 0; i < 100; i++ { + istr := strconv.Itoa(i) start := time.Now() - object, err := mc.GetObject(context.Background(), "bench1", "element"+string(i), minio.GetObjectOptions{}) + object, err := mc.GetObject(context.Background(), "bench1", "element"+istr, minio.GetObjectOptions{}) if err != nil { log.Fatal(err) return @@ -91,8 +103,9 @@ func main() { } for i := 0; i < 100; i++ { + istr := strconv.Itoa(i) start := time.Now() - err = mc.RemoveObject(context.Background(), "bench1", "element"+string(i), minio.RemoveObjectOptions{}) + err = mc.RemoveObject(context.Background(), "bench1", "element"+istr, minio.RemoveObjectOptions{}) elapsed := time.Since(start) if err != nil { log.Fatal(err)