doc_custom.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Upload Managers
  2. //
  3. // The s3manager package's Uploader provides concurrent upload of content to S3
  4. // by taking advantage of S3's Multipart APIs. The Uploader also supports both
  5. // io.Reader for streaming uploads, and will also take advantage of io.ReadSeeker
  6. // for optimizations if the Body satisfies that type. Once the Uploader instance
  7. // is created you can call Upload concurrently from multiple goroutines safely.
  8. //
  9. // // The session the S3 Uploader will use
  10. // sess := session.Must(session.NewSession())
  11. //
  12. // // Create an uploader with the session and default options
  13. // uploader := s3manager.NewUploader(sess)
  14. //
  15. // f, err := os.Open(filename)
  16. // if err != nil {
  17. // return fmt.Errorf("failed to open file %q, %v", filename, err)
  18. // }
  19. //
  20. // // Upload the file to S3.
  21. // result, err := uploader.Upload(&s3manager.UploadInput{
  22. // Bucket: aws.String(myBucket),
  23. // Key: aws.String(myString),
  24. // Body: f,
  25. // })
  26. // if err != nil {
  27. // return fmt.Errorf("failed to upload file, %v", err)
  28. // }
  29. // fmt.Printf("file uploaded to, %s\n", aws.StringValue(result.Location))
  30. //
  31. // See the s3manager package's Uploader type documentation for more information.
  32. // https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#Uploader
  33. //
  34. // # Download Manager
  35. //
  36. // The s3manager package's Downloader provides concurrently downloading of Objects
  37. // from S3. The Downloader will write S3 Object content with an io.WriterAt.
  38. // Once the Downloader instance is created you can call Download concurrently from
  39. // multiple goroutines safely.
  40. //
  41. // // The session the S3 Downloader will use
  42. // sess := session.Must(session.NewSession())
  43. //
  44. // // Create a downloader with the session and default options
  45. // downloader := s3manager.NewDownloader(sess)
  46. //
  47. // // Create a file to write the S3 Object contents to.
  48. // f, err := os.Create(filename)
  49. // if err != nil {
  50. // return fmt.Errorf("failed to create file %q, %v", filename, err)
  51. // }
  52. //
  53. // // Write the contents of S3 Object to the file
  54. // n, err := downloader.Download(f, &s3.GetObjectInput{
  55. // Bucket: aws.String(myBucket),
  56. // Key: aws.String(myString),
  57. // })
  58. // if err != nil {
  59. // return fmt.Errorf("failed to download file, %v", err)
  60. // }
  61. // fmt.Printf("file downloaded, %d bytes\n", n)
  62. //
  63. // See the s3manager package's Downloader type documentation for more information.
  64. // https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#Downloader
  65. //
  66. // # Automatic URI cleaning
  67. //
  68. // Interacting with objects whose keys contain adjacent slashes (e.g. bucketname/foo//bar/objectname)
  69. // requires setting DisableRestProtocolURICleaning to true in the aws.Config struct
  70. // used by the service client.
  71. //
  72. // svc := s3.New(sess, &aws.Config{
  73. // DisableRestProtocolURICleaning: aws.Bool(true),
  74. // })
  75. // out, err := svc.GetObject(&s3.GetObjectInput {
  76. // Bucket: aws.String("bucketname"),
  77. // Key: aws.String("//foo//bar//moo"),
  78. // })
  79. //
  80. // # Get Bucket Region
  81. //
  82. // GetBucketRegion will attempt to get the region for a bucket using a region
  83. // hint to determine which AWS partition to perform the query on. Use this utility
  84. // to determine the region a bucket is in.
  85. //
  86. // sess := session.Must(session.NewSession())
  87. //
  88. // bucket := "my-bucket"
  89. // region, err := s3manager.GetBucketRegion(ctx, sess, bucket, "us-west-2")
  90. // if err != nil {
  91. // if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "NotFound" {
  92. // fmt.Fprintf(os.Stderr, "unable to find bucket %s's region not found\n", bucket)
  93. // }
  94. // return err
  95. // }
  96. // fmt.Printf("Bucket %s is in %s region\n", bucket, region)
  97. //
  98. // See the s3manager package's GetBucketRegion function documentation for more information
  99. // https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3manager/#GetBucketRegion
  100. //
  101. // # S3 Crypto Client
  102. //
  103. // The s3crypto package provides the tools to upload and download encrypted
  104. // content from S3. The Encryption and Decryption clients can be used concurrently
  105. // once the client is created.
  106. //
  107. // See the s3crypto package documentation for more information.
  108. // https://docs.aws.amazon.com/sdk-for-go/api/service/s3/s3crypto/
  109. package s3