Documentation
¶
Overview ¶
Package s3 signs HTTP requests for Amazon S3 and compatible services.
See http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/RESTAuthentication.html.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultService = &Service{Domain: "amazonaws.com"}
The default Service used by Sign.
Functions ¶
func AmazonBucket ¶
AmazonBucket returns up to last section of subdomain. Intended to be used with Amazon S3 service: "johnsmith.s3-eu-west-1" => "johnsmith".
func IdentityBucket ¶
IdentityBucket returns subdomain as-is.
func Sign ¶
Sign signs an HTTP request with the given S3 keys.
This function is shorthand for DefaultService.Sign(r, k).
Example ¶
package main
import (
"fmt"
"github.com/kr/s3"
"log"
"net/http"
"os"
"strings"
"time"
)
func main() {
keys := s3.Keys{
AccessKey: os.Getenv("S3_ACCESS_KEY"),
SecretKey: os.Getenv("S3_SECRET_KEY"),
}
data := strings.NewReader("hello, world")
r, _ := http.NewRequest("PUT", "https://example.s3.amazonaws.com/foo", data)
r.ContentLength = int64(data.Len())
r.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
r.Header.Set("X-Amz-Acl", "public-read")
s3.Sign(r, keys)
resp, err := http.DefaultClient.Do(r)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.StatusCode)
}
Output:
Types ¶
type Keys ¶
type Keys struct {
AccessKey string
SecretKey string
// Used for temporary security credentials. Leave blank to use
// standard AWS Account or IAM credentials.
// See http://docs.aws.amazon.com/AmazonS3/latest/dev/MakingRequests.html#TypesofSecurityCredentials
SecurityToken string
}
Keys holds a set of Amazon Security Credentials.
type Service ¶
type Service struct {
Domain string // service root domain, used to extract subdomain from an http.Request and pass it to Bucket
Bucket func(subdomain string) string // function used to derive a bucket name from subdomain; if nil, AmazonBucket is used
}
Service represents an S3-compatible service.
Click to show internal directories.
Click to hide internal directories.