service.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package s3
  3. import (
  4. "github.com/ks3sdklib/aws-sdk-go/aws"
  5. "github.com/ks3sdklib/aws-sdk-go/internal/protocol/body"
  6. "github.com/ks3sdklib/aws-sdk-go/internal/signer/v2"
  7. "github.com/ks3sdklib/aws-sdk-go/internal/signer/v4"
  8. "strings"
  9. )
  10. // S3 is a client for Amazon S3.
  11. type S3 struct {
  12. *aws.Service
  13. }
  14. // Used for custom service initialization logic
  15. var initService func(*aws.Service)
  16. // Used for custom request initialization logic
  17. var initRequest func(*aws.Request)
  18. // New returns a new S3 client.
  19. func New(config *aws.Config) *S3 {
  20. service := &aws.Service{
  21. Config: aws.DefaultConfig.Merge(config),
  22. ServiceName: "s3",
  23. APIVersion: "2006-03-01",
  24. }
  25. service.Initialize()
  26. // Handlers
  27. if service.Config.SignerVersion == "V4" || service.Config.SignerVersion == "V4_UNSIGNED_PAYLOAD_SIGNER" {
  28. service.Handlers.Sign.PushBack(v4.Sign)
  29. } else {
  30. service.Handlers.Sign.PushBack(v2.Sign)
  31. }
  32. service.Handlers.Build.PushBack(body.Build)
  33. service.Handlers.Unmarshal.PushBack(body.UnmarshalBody)
  34. service.Handlers.UnmarshalMeta.PushBack(body.UnmarshalMeta)
  35. service.Handlers.UnmarshalError.PushBack(body.UnmarshalError)
  36. // Run custom service initialization if present
  37. if initService != nil {
  38. initService(service)
  39. }
  40. return &S3{service}
  41. }
  42. // newRequest creates a new request for a S3 operation and runs any
  43. // custom request initialization.
  44. func (c *S3) newRequest(op *aws.Operation, params, data interface{}) *aws.Request {
  45. r := aws.NewRequest(c.Service, op, params, data)
  46. if r.Config.DomainMode {
  47. r.HTTPRequest.URL.Path = strings.Replace(r.HTTPRequest.URL.Path, "/{Bucket}", "", -1)
  48. if r.HTTPRequest.URL.Path == "" {
  49. r.HTTPRequest.URL.Path = "/"
  50. }
  51. } else {
  52. updateHostWithBucket(r)
  53. }
  54. // Run custom request initialization if present
  55. if initRequest != nil {
  56. initRequest(r)
  57. }
  58. return r
  59. }