service.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Code generated by private/model/cli/gen-api/main.go. 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. // Please also see https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15
  18. type EC2 struct {
  19. *client.Client
  20. }
  21. // Used for custom client initialization logic
  22. var initClient func(*client.Client)
  23. // Used for custom request initialization logic
  24. var initRequest func(*request.Request)
  25. // Service information constants
  26. const (
  27. ServiceName = "ec2" // Service endpoint prefix API calls made to.
  28. EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
  29. )
  30. // New creates a new instance of the EC2 client with a session.
  31. // If additional configuration is needed for the client instance use the optional
  32. // aws.Config parameter to add your extra config.
  33. //
  34. // Example:
  35. // // Create a EC2 client from just a session.
  36. // svc := ec2.New(mySession)
  37. //
  38. // // Create a EC2 client with additional configuration
  39. // svc := ec2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
  40. func New(p client.ConfigProvider, cfgs ...*aws.Config) *EC2 {
  41. c := p.ClientConfig(EndpointsID, cfgs...)
  42. return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
  43. }
  44. // newClient creates, initializes and returns a new service client instance.
  45. func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *EC2 {
  46. svc := &EC2{
  47. Client: client.New(
  48. cfg,
  49. metadata.ClientInfo{
  50. ServiceName: ServiceName,
  51. SigningName: signingName,
  52. SigningRegion: signingRegion,
  53. Endpoint: endpoint,
  54. APIVersion: "2016-11-15",
  55. },
  56. handlers,
  57. ),
  58. }
  59. // Handlers
  60. svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  61. svc.Handlers.Build.PushBackNamed(ec2query.BuildHandler)
  62. svc.Handlers.Unmarshal.PushBackNamed(ec2query.UnmarshalHandler)
  63. svc.Handlers.UnmarshalMeta.PushBackNamed(ec2query.UnmarshalMetaHandler)
  64. svc.Handlers.UnmarshalError.PushBackNamed(ec2query.UnmarshalErrorHandler)
  65. // Run custom client initialization if present
  66. if initClient != nil {
  67. initClient(svc.Client)
  68. }
  69. return svc
  70. }
  71. // newRequest creates a new request for a EC2 operation and runs any
  72. // custom request initialization.
  73. func (c *EC2) newRequest(op *request.Operation, params, data interface{}) *request.Request {
  74. req := c.NewRequest(op, params, data)
  75. // Run custom request initialization if present
  76. if initRequest != nil {
  77. initRequest(req)
  78. }
  79. return req
  80. }