Fix bug
This commit is contained in:
parent
c16070cae9
commit
8713253df0
1 changed files with 22 additions and 9 deletions
31
main.go
31
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)
|
||||
|
|
Loading…
Reference in a new issue