doc.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Copyright 2018 Google LLC
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package cloud implements a more golang friendly interface to the GCE compute
  14. // API. The code in this package is generated automatically via the generator
  15. // implemented in "gen/main.go". The code generator creates the basic CRUD
  16. // actions for the given resource: "Insert", "Get", "List" and "Delete".
  17. // Additional methods by customizing the ServiceInfo object (see below).
  18. // Generated code includes a full mock of the GCE compute API.
  19. //
  20. // Usage
  21. //
  22. // The root of the GCE compute API is the interface "Cloud". Code written using
  23. // Cloud can be used against the actual implementation "GCE" or "MockGCE".
  24. //
  25. // func foo(cloud Cloud) {
  26. // igs, err := cloud.InstanceGroups().List(ctx, "us-central1-b", filter.None)
  27. // ...
  28. // }
  29. // // Run foo against the actual cloud.
  30. // foo(NewGCE(&Service{...}))
  31. // // Run foo with a mock.
  32. // foo(NewMockGCE())
  33. //
  34. // Rate limiting and routing
  35. //
  36. // The generated code allows for custom policies for operation rate limiting
  37. // and GCE project routing. See RateLimiter and ProjectRouter for more details.
  38. //
  39. // Mocks
  40. //
  41. // Mocks are automatically generated for each type implementing basic logic for
  42. // resource manipulation. This eliminates the boilerplate required to mock GCE
  43. // functionality. Each method will also have a corresponding "xxxHook"
  44. // function generated in the mock structure where unit test code can hook the
  45. // execution of the method.
  46. //
  47. // Mocks for different versions of the same service will share the same set of
  48. // objects, i.e. an alpha object will be visible with beta and GA methods.
  49. // Note that translation is done with JSON serialization between the API versions.
  50. //
  51. // Changing service code generation
  52. //
  53. // The list of services to generate is contained in "meta/meta.go". To add a
  54. // service, add an entry to the list "meta.AllServices". An example entry:
  55. //
  56. // &ServiceInfo{
  57. // Object: "InstanceGroup", // Name of the object type.
  58. // Service: "InstanceGroups", // Name of the service.
  59. // Resource: "instanceGroups", // Lowercase resource name (as appears in the URL).
  60. // version: meta.VersionAlpha, // API version (one entry per version is needed).
  61. // keyType: Zonal, // What kind of resource this is.
  62. // serviceType: reflect.TypeOf(&alpha.InstanceGroupsService{}), // Associated golang type.
  63. // additionalMethods: []string{ // Additional methods to generate code for.
  64. // "SetNamedPorts",
  65. // },
  66. // options: <options> // Or'd ("|") together.
  67. // }
  68. //
  69. // Read-only objects
  70. //
  71. // Services such as Regions and Zones do not allow for mutations. Specify
  72. // "ReadOnly" in ServiceInfo.options to omit the mutation methods.
  73. //
  74. // Adding custom methods
  75. //
  76. // Some methods that may not be properly handled by the generated code. To enable
  77. // addition of custom code to the generated mocks, set the "CustomOps" option
  78. // in "meta.ServiceInfo" entry. This will make the generated service interface
  79. // embed a "<ServiceName>Ops" interface. This interface MUST be written by hand
  80. // and contain the custom method logic. Corresponding methods must be added to
  81. // the corresponding Mockxxx and GCExxx struct types.
  82. //
  83. // // In "meta/meta.go":
  84. // &ServiceInfo{
  85. // Object: "InstanceGroup",
  86. // ...
  87. // options: CustomOps,
  88. // }
  89. //
  90. // // In the generated code "gen.go":
  91. // type InstanceGroups interface {
  92. // InstanceGroupsOps // Added by CustomOps option.
  93. // ...
  94. // }
  95. //
  96. // // In hand written file:
  97. // type InstanceGroupsOps interface {
  98. // MyMethod()
  99. // }
  100. //
  101. // func (mock *MockInstanceGroups) MyMethod() {
  102. // // Custom mock implementation.
  103. // }
  104. //
  105. // func (gce *GCEInstanceGroups) MyMethod() {
  106. // // Custom implementation.
  107. // }
  108. //
  109. // Update generated codes
  110. //
  111. // Run hack/update-cloudprovider-gce.sh to update the generated codes.
  112. //
  113. package cloud