Documentation ¶
Index ¶
- Constants
- type DeleteInput
- type DetailsInput
- type DetailsResponse
- type DownloadInput
- type IAMResponse
- type PolicyJSON
- type PresignedInput
- type PutResponse
- type S3
- func (s3 *S3) CreateUploadPolicies(uploadConfig UploadConfig) (UploadPolicies, error)
- func (s3 *S3) FileDelete(u DeleteInput) error
- func (s3 *S3) FileDetails(u DetailsInput) (DetailsResponse, error)
- func (s3 *S3) FileDownload(u DownloadInput) (io.ReadCloser, error)
- func (s3 *S3) FilePut(u UploadInput) (PutResponse, error)
- func (s3 *S3) FileUpload(u UploadInput) (UploadResponse, error)
- func (s3 *S3) GeneratePresignedURL(in PresignedInput) string
- func (s3 *S3) SetClient(client *http.Client) *S3
- func (s3 *S3) SetEndpoint(uri string) *S3
- func (s3 *S3) SetIAMData(iamResp IAMResponse)
- func (s3 *S3) SetToken(token string) *S3
- type UploadConfig
- type UploadInput
- type UploadPolicies
- type UploadResponse
Constants ¶
const (
// AMZMetaPrefix to prefix metadata key.
AMZMetaPrefix = "x-amz-meta-"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeleteInput ¶
DeleteInput is passed to FileDelete as a parameter.
type DetailsInput ¶ added in v0.7.0
DetailsInput is passed to FileDetails as a parameter.
type DetailsResponse ¶ added in v0.7.0
type DetailsResponse struct { ContentType string ContentLength string AcceptRanges string Date string Etag string LastModified string Server string AmzID2 string AmzRequestID string AmzMeta map[string]string ExtraHeaders map[string]string }
DetailsResponse is returned by FileDetails.
type DownloadInput ¶ added in v0.5.0
DownloadInput is passed to FileDownload as a parameter.
type IAMResponse ¶
type IAMResponse struct { Code string `json:"Code"` LastUpdated string `json:"LastUpdated"` Type string `json:"Type"` AccessKeyID string `json:"AccessKeyId"` SecretAccessKey string `json:"SecretAccessKey"` Token string `json:"Token"` Expiration string `json:"Expiration"` }
IAMResponse is used by NewUsingIAM to auto detect the credentials.
type PolicyJSON ¶
type PolicyJSON struct { Expiration string `json:"expiration"` Conditions []interface{} `json:"conditions"` }
PolicyJSON is policy rule.
type PresignedInput ¶
type PresignedInput struct { Bucket string ObjectKey string Method string Timestamp time.Time ExtraHeaders map[string]string ExpirySeconds int Protocol string Endpoint string }
PresignedInput is passed to GeneratePresignedURL as a parameter.
type PutResponse ¶ added in v0.8.0
PutResponse is returned when the action is successful, and the service sends back an HTTP 200 response. The response returns ETag along with HTTP headers.
type S3 ¶
type S3 struct { AccessKey string SecretKey string Region string Client *http.Client Token string Endpoint string URIFormat string }
S3 provides a wrapper around your S3 credentials.
func NewUsingIAM ¶
NewUsingIAM automatically generates an Instance of S3 using instance metatdata.
func (*S3) CreateUploadPolicies ¶
func (s3 *S3) CreateUploadPolicies(uploadConfig UploadConfig) (UploadPolicies, error)
CreateUploadPolicies creates amazon s3 sigv4 compatible policy and signing keys with the signature returns the upload policy. https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
func (*S3) FileDelete ¶
func (s3 *S3) FileDelete(u DeleteInput) error
FileDelete makes a DELETE call with the file written as multipart and on successful upload, checks for 204 No Content.
func (*S3) FileDetails ¶ added in v0.7.0
func (s3 *S3) FileDetails(u DetailsInput) (DetailsResponse, error)
func (*S3) FileDownload ¶ added in v0.5.0
func (s3 *S3) FileDownload(u DownloadInput) (io.ReadCloser, error)
FileDownload makes a GET call and returns a io.ReadCloser. After reading the response body, ensure closing the response.
func (*S3) FilePut ¶ added in v0.8.0
func (s3 *S3) FilePut(u UploadInput) (PutResponse, error)
FilePut makes a PUT call to S3.
func (*S3) FileUpload ¶
func (s3 *S3) FileUpload(u UploadInput) (UploadResponse, error)
FileUpload makes a POST call with the file written as multipart and on successful upload, checks for 200 OK.
func (*S3) GeneratePresignedURL ¶
func (s3 *S3) GeneratePresignedURL(in PresignedInput) string
GeneratePresignedURL creates a Presigned URL that can be used for Authentication using Query Parameters. (https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html)
func (*S3) SetClient ¶ added in v0.3.0
SetClient can be used to set the http client to be used by the package. If client passed is nil, http.DefaultClient is used.
func (*S3) SetEndpoint ¶ added in v0.4.0
SetEndpoint can be used to the set a custom endpoint for using an alternate instance compatible with the s3 API. If no protocol is included in the URI, defaults to HTTPS.
func (*S3) SetIAMData ¶ added in v0.8.4
func (s3 *S3) SetIAMData(iamResp IAMResponse)
setIAMData sets the IAM data on the S3 instance.
type UploadConfig ¶
type UploadConfig struct { // Required BucketName string ObjectKey string ContentType string ContentDisposition string ACL string FileSize int64 // Optional UploadURL string Expiration time.Duration MetaData map[string]string }
UploadConfig generate policies from config for POST requests to S3 using Signing V4.
type UploadInput ¶
type UploadInput struct { // essential fields Bucket string ObjectKey string FileName string ContentType string // optional fields ContentDisposition string ACL string // Setting key/value pairs adds user-defined metadata // keys to the object, prefixed with AMZMetaPrefix. CustomMetadata map[string]string Body io.ReadSeeker }
UploadInput is passed to FileUpload as a parameter.
type UploadPolicies ¶
UploadPolicies Amazon s3 upload policies.
type UploadResponse ¶ added in v0.2.0
type UploadResponse struct { Location string `xml:"Location"` Bucket string `xml:"Bucket"` Key string `xml:"Key"` ETag string `xml:"ETag"` }
UploadResponse receives the following XML in case of success, since we set a 201 response from S3. Sample response:
<PostResponse> <Location>https://s3.amazonaws.com/link-to-the-file</Location> <Bucket>s3-bucket</Bucket> <Key>development/8614bd40-691b-4668-9241-3b342c6cf429/image.jpg</Key> <ETag>"32-bit-tag"</ETag> </PostResponse>