service.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // EC2 provides the API operation methods for making requests to
  12. // Amazon Elastic Compute Cloud. See this package's package overview docs
  13. // for details on the service.
  14. //
  15. // EC2 methods are safe to use concurrently. It is not safe to
  16. // modify mutate any of the struct'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. // Service information constants
  25. const (
  26. ServiceName = "ec2" // Service endpoint prefix API calls made to.
  27. EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
  28. )
  29. // New creates a new instance of the EC2 client with a session.
  30. // If additional configuration is needed for the client instance use the optional
  31. // aws.Config parameter to add your extra config.
  32. //
  33. // Example:
  34. // // Create a EC2 client from just a session.
  35. // svc := ec2.New(mySession)
  36. //
  37. // // Create a EC2 client with additional configuration
  38. // svc := ec2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
  39. func New(p client.ConfigProvider, cfgs ...*aws.Config) *EC2 {
  40. c := p.ClientConfig(EndpointsID, cfgs...)
  41. return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
  42. }
  43. // newClient creates, initializes and returns a new service client instance.
  44. func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *EC2 {
  45. svc := &EC2{
  46. Client: client.New(
  47. cfg,
  48. metadata.ClientInfo{
  49. ServiceName: ServiceName,
  50. SigningName: signingName,
  51. SigningRegion: signingRegion,
  52. Endpoint: endpoint,
  53. APIVersion: "2016-11-15",
  54. },
  55. handlers,
  56. ),
  57. }
  58. // Handlers
  59. svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  60. svc.Handlers.Build.PushBackNamed(ec2query.BuildHandler)
  61. svc.Handlers.Unmarshal.PushBackNamed(ec2query.UnmarshalHandler)
  62. svc.Handlers.UnmarshalMeta.PushBackNamed(ec2query.UnmarshalMetaHandler)
  63. svc.Handlers.UnmarshalError.PushBackNamed(ec2query.UnmarshalErrorHandler)
  64. // Run custom client initialization if present
  65. if initClient != nil {
  66. initClient(svc.Client)
  67. }
  68. return svc
  69. }
  70. // newRequest creates a new request for a EC2 operation and runs any
  71. // custom request initialization.
  72. func (c *EC2) newRequest(op *request.Operation, params, data interface{}) *request.Request {
  73. req := c.NewRequest(op, params, data)
  74. // Run custom request initialization if present
  75. if initRequest != nil {
  76. initRequest(req)
  77. }
  78. return req
  79. }