Documentation ¶
Overview ¶
Package s3 signs HTTP requests for Amazon S3 and compatible services.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultService = &Service{Domain: "amazonaws.com"}
DefaultService is the default Service used by Sign.
Functions ¶
func AmazonBucket ¶
AmazonBucket returns everything up to the last '.' in subdomain. It is designed to be used with the Amazon service.
"johnsmith.s3" becomes "johnsmith" "johnsmith.s3-eu-west-1" becomes "johnsmith" "www.example.com.s3" becomes "www.example.com"
func IdentityBucket ¶
IdentityBucket returns subdomain. It is designed to be used with S3-compatible services that treat the entire subdomain as the bucket name, for example storage.io.
func Sign ¶
Sign signs an HTTP request with the given S3 keys.
This function is a wrapper around DefaultService.Sign.
Example ¶
package main import ( "fmt" "github.com/500px/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 // SecurityToken is used for temporary security credentials. // If set, it will be added to header field X-Amz-Security-Token // before signing a request. SecurityToken string }
Keys holds a set of Amazon Security Credentials.
type Service ¶
type Service struct { // Domain is the service's root domain. It is used to extract // the subdomain from an http.Request before passing the // subdomain to Bucket. Domain string // Bucket derives the bucket name from a subdomain. // If nil, AmazonBucket is used. Bucket func(subdomain string) string }
Service represents an S3-compatible service.
Click to show internal directories.
Click to hide internal directories.