Created
September 21, 2022 19:32
-
-
Save AhmedAbouelkher/958b1d0bf690b16cd62503cf3462f9f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
"github.com/aws/aws-sdk-go-v2/aws" | |
"github.com/aws/aws-sdk-go-v2/credentials" | |
"github.com/aws/aws-sdk-go-v2/service/s3" | |
) | |
var ( | |
ctx = context.Background() | |
accessKeyID = "ACCESS_KEY_ID" | |
secretAccessKey = "SECRET_ACCCESS_KEY" | |
) | |
func main() { | |
cfg := aws.Config{ | |
Region: "eu-central-2", | |
Credentials: credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, ""), | |
EndpointResolver: aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) { | |
return aws.Endpoint{ | |
URL: "http://localhost:9000", | |
}, nil | |
}), | |
} | |
cl := s3.NewFromConfig(cfg) | |
out, err := cl.ListObjects(ctx, &s3.ListObjectsInput{ | |
Bucket: aws.String("new"), | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, v := range out.Contents { | |
log.Println(*v.Key) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
"github.com/minio/minio-go/v7" | |
"github.com/minio/minio-go/v7/pkg/credentials" | |
) | |
var ( | |
ctx = context.Background() | |
accessKeyID = "ACCESS_KEY_ID" | |
secretAccessKey = "SECRET_ACCCESS_KEY" | |
) | |
func main() { | |
endpoint := "localhost:9000" | |
// Initialize minio client object. | |
minioClient, err := minio.New(endpoint, &minio.Options{ | |
Region: "eu-central-2", | |
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), | |
}) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
out := minioClient.ListObjects(ctx, "new", minio.ListObjectsOptions{}) | |
for inf := range out { | |
log.Println(inf.Key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment