service.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package ec2
  3. import (
  4. "github.com/aws/aws-sdk-go/aws"
  5. "github.com/aws/aws-sdk-go/aws/client"
  6. "github.com/aws/aws-sdk-go/aws/client/metadata"
  7. "github.com/aws/aws-sdk-go/aws/request"
  8. "github.com/aws/aws-sdk-go/aws/signer/v4"
  9. "github.com/aws/aws-sdk-go/private/protocol/ec2query"
  10. )
  11. // Amazon Elastic Compute Cloud (Amazon EC2) provides resizable computing capacity
  12. // in the Amazon Web Services (AWS) cloud. Using Amazon EC2 eliminates your
  13. // need to invest in hardware up front, so you can develop and deploy applications
  14. // faster.
  15. //The service client's operations are safe to be used concurrently.
  16. // It is not safe to mutate any of the client's properties though.
  17. type EC2 struct {
  18. *client.Client
  19. }
  20. // Used for custom client initialization logic
  21. var initClient func(*client.Client)
  22. // Used for custom request initialization logic
  23. var initRequest func(*request.Request)
  24. // A ServiceName is the name of the service the client will make API calls to.
  25. const ServiceName = "ec2"
  26. // New creates a new instance of the EC2 client with a session.
  27. // If additional configuration is needed for the client instance use the optional
  28. // aws.Config parameter to add your extra config.
  29. //
  30. // Example:
  31. // // Create a EC2 client from just a session.
  32. // svc := ec2.New(mySession)
  33. //
  34. // // Create a EC2 client with additional configuration
  35. // svc := ec2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
  36. func New(p client.ConfigProvider, cfgs ...*aws.Config) *EC2 {
  37. c := p.ClientConfig(ServiceName, cfgs...)
  38. return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion)
  39. }
  40. // newClient creates, initializes and returns a new service client instance.
  41. func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion string) *EC2 {
  42. svc := &EC2{
  43. Client: client.New(
  44. cfg,
  45. metadata.ClientInfo{
  46. ServiceName: ServiceName,
  47. SigningRegion: signingRegion,
  48. Endpoint: endpoint,
  49. APIVersion: "2016-09-15",
  50. },
  51. handlers,
  52. ),
  53. }
  54. // Handlers
  55. svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  56. svc.Handlers.Build.PushBackNamed(ec2query.BuildHandler)
  57. svc.Handlers.Unmarshal.PushBackNamed(ec2query.UnmarshalHandler)
  58. svc.Handlers.UnmarshalMeta.PushBackNamed(ec2query.UnmarshalMetaHandler)
  59. svc.Handlers.UnmarshalError.PushBackNamed(ec2query.UnmarshalErrorHandler)
  60. // Run custom client initialization if present
  61. if initClient != nil {
  62. initClient(svc.Client)
  63. }
  64. return svc
  65. }
  66. // newRequest creates a new request for a EC2 operation and runs any
  67. // custom request initialization.
  68. func (c *EC2) newRequest(op *request.Operation, params, data interface{}) *request.Request {
  69. req := c.NewRequest(op, params, data)
  70. // Run custom request initialization if present
  71. if initRequest != nil {
  72. initRequest(req)
  73. }
  74. return req
  75. }