amazon s3 - Go Connecting to S3 -
working on learning go, , writing component manage pictures.
i've been looking @ s3 library here: https://godoc.org/launchpad.net/goamz/s3#acl
in node, use knox client , connect bucket this:
var bucket = knox.createclient({ key: config.get('aws_key'), secret: config.get('aws_secret'), bucket: "bucketname" });
in go s3 library see of functions need work s3 bucket, can't find connect function - similar 1 above.
so far, i've found in docs:
type auth struct { accesskey, secretkey string }
and seems need call function:
func envauth() (auth auth, err error)
this envauth function:
func envauth() (auth auth, err error) { auth.accesskey = os.getenv("aws_access_key_id") auth.secretkey = os.getenv("aws_secret_access_key") // fallback ec2_ env variables if aws_ variants not used. if auth.accesskey == "" && auth.secretkey == "" { auth.accesskey = os.getenv("ec2_access_key") auth.secretkey = os.getenv("ec2_secret_key") } if auth.accesskey == "" { err = errors.new("aws_access_key_id not found in environment") } if auth.secretkey == "" { err = errors.new("aws_secret_access_key not found in environment") } return }
in s3 docs, see of things need. unsure how use library, first time use go library.
a guide on connecting aws/s3, making delete call helpful!
many :)
it's easier you've thought. sample code lists bucket. have use credentials , bucket name, of course...
package main import ( "fmt" "launchpad.net/goamz/aws" "launchpad.net/goamz/s3" "log" ) func main() { auth := aws.auth{ accesskey: "asdfasdfasdfasdk", secretkey: "dsfsdfdwesdadsfasdfadfdsfasdf", } euwest := aws.euwest connection := s3.new(auth, euwest) mybucket := connection.bucket("mytotallysecretbucket") res, err := mybucket.list("", "", "", 1000) if err != nil { log.fatal(err) } _, v := range res.contents { fmt.println(v.key) } }
Comments
Post a Comment