Skip to content

Instantly share code, notes, and snippets.

@dragonfax
Created August 28, 2015 01:24
Show Gist options
  • Save dragonfax/f3d26a59033f59877bf8 to your computer and use it in GitHub Desktop.
Save dragonfax/f3d26a59033f59877bf8 to your computer and use it in GitHub Desktop.
simple client to access Riak CS using aws-sdk-go
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"),
Region: aws.String("US"),
S3ForcePathStyle: aws.Bool(true),
DisableSSL: aws.Bool(true),
// LogLevel: aws.LogLevel(aws.LogDebug),
})
// svc.AddDebugHandlers()
listout, err := svc.ListObjects(&s3.ListObjectsInput{
Bucket: aws.String("blah"),
})
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("blah"),
Key: aws.String("test_file"),
})
if err != nil {
panic(err)
}
fmt.Printf("%v\n", putout)
getout, err := svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String("blah"),
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