Created
November 28, 2017 21:59
-
-
Save krishnasrinivas/23ed37f564d18b624da9436b7714e3c1 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 ( | |
"fmt" | |
"os" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
"github.com/aws/aws-sdk-go/service/s3/s3manager" | |
) | |
func main() { | |
bucket := aws.String("test") | |
key := aws.String("passwd") | |
// Configure to use Minio Server | |
s3Config := &aws.Config{ | |
Credentials: credentials.NewStaticCredentials("SXO8VW2OFKKP2OG7AC85", "CKWSSgrUgvfUMTaNBkB63exet4WW+uNhQvi91Bc3", ""), | |
Endpoint: aws.String("http://localhost:9000"), | |
Region: aws.String("us-east-1"), | |
DisableSSL: aws.Bool(true), | |
S3ForcePathStyle: aws.Bool(true), | |
} | |
newSession := session.New(s3Config) | |
file, err := os.Create("testobject_local") | |
if err != nil { | |
fmt.Println("Failed to create file", err) | |
return | |
} | |
defer file.Close() | |
downloader := s3manager.NewDownloader(newSession) | |
numBytes, err := downloader.Download(file, | |
&s3.GetObjectInput{ | |
Bucket: bucket, | |
Key: key, | |
}) | |
if err != nil { | |
fmt.Println("Failed to download file", err) | |
return | |
} | |
fmt.Println("Downloaded file", file.Name(), numBytes, "bytes") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment