-
-
Save lucasallan/515572309c5311a3bc07a57a87b0cc4e to your computer and use it in GitHub Desktop.
example Riak CS (s3 API) client using aws-sdk-go
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 ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
func main() { | |
key := "XXXXX" | |
secret := "XXXXX" | |
svc := s3.New(&aws.Config{ | |
Credentials: credentials.NewStaticCredentials( | |
key, | |
secret, | |
""), | |
Endpoint: aws.String("192.168.45.42:8080"), // Where Riak CS was running (via docker) | |
Region: aws.String("US"), | |
S3ForcePathStyle: aws.Bool(true), | |
DisableSSL: aws.Bool(true), | |
}) | |
listout, err := svc.ListObjects(&s3.ListObjectsInput{ | |
Bucket: aws.String("test"), | |
}) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%v\n", listout) | |
putout, err := svc.PutObject(&s3.PutObjectInput{ | |
Body: bytes.NewReader([]byte("this is a test")), | |
Bucket: aws.String("test"), | |
Key: aws.String("test_file"), | |
}) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%v\n", putout) | |
getout, err := svc.GetObject(&s3.GetObjectInput{ | |
Bucket: aws.String("test"), | |
Key: aws.String("test_file"), | |
}) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%v\n", getout) | |
buf, err := ioutil.ReadAll(getout.Body) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(buf)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment