| 1 |
// Copyright 2025 Google LLC |
| 2 |
// |
| 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 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| 16 |
|
| 17 |
package alloydb_test |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
|
| 22 |
alloydb "cloud.google.com/go/alloydb/apiv1beta" |
| 23 |
alloydbpb "cloud.google.com/go/alloydb/apiv1beta/alloydbpb" |
| 24 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 25 |
"google.golang.org/api/iterator" |
| 26 |
locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 27 |
) |
| 28 |
|
| 29 |
func ExampleNewAlloyDBCSQLAdminClient() { |
| 30 |
ctx := context.Background() |
| 31 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 32 |
// It will require modifications to work: |
| 33 |
// - It may require correct/in-range values for request initialization. |
| 34 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 35 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 36 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 37 |
if err != nil { |
| 38 |
// TODO: Handle error. |
| 39 |
} |
| 40 |
defer c.Close() |
| 41 |
|
| 42 |
// TODO: Use client. |
| 43 |
_ = c |
| 44 |
} |
| 45 |
|
| 46 |
func ExampleNewAlloyDBCSQLAdminRESTClient() { |
| 47 |
ctx := context.Background() |
| 48 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 49 |
// It will require modifications to work: |
| 50 |
// - It may require correct/in-range values for request initialization. |
| 51 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 52 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 53 |
c, err := alloydb.NewAlloyDBCSQLAdminRESTClient(ctx) |
| 54 |
if err != nil { |
| 55 |
// TODO: Handle error. |
| 56 |
} |
| 57 |
defer c.Close() |
| 58 |
|
| 59 |
// TODO: Use client. |
| 60 |
_ = c |
| 61 |
} |
| 62 |
|
| 63 |
func ExampleAlloyDBCSQLAdminClient_RestoreFromCloudSQL() { |
| 64 |
ctx := context.Background() |
| 65 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 66 |
// It will require modifications to work: |
| 67 |
// - It may require correct/in-range values for request initialization. |
| 68 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 69 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 70 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 71 |
if err != nil { |
| 72 |
// TODO: Handle error. |
| 73 |
} |
| 74 |
defer c.Close() |
| 75 |
|
| 76 |
req := &alloydbpb.RestoreFromCloudSQLRequest{ |
| 77 |
// TODO: Fill request struct fields. |
| 78 |
// See https://pkg.go.dev/cloud.google.com/go/alloydb/apiv1beta/alloydbpb#RestoreFromCloudSQLRequest. |
| 79 |
} |
| 80 |
op, err := c.RestoreFromCloudSQL(ctx, req) |
| 81 |
if err != nil { |
| 82 |
// TODO: Handle error. |
| 83 |
} |
| 84 |
|
| 85 |
resp, err := op.Wait(ctx) |
| 86 |
if err != nil { |
| 87 |
// TODO: Handle error. |
| 88 |
} |
| 89 |
// TODO: Use resp. |
| 90 |
_ = resp |
| 91 |
} |
| 92 |
|
| 93 |
func ExampleAlloyDBCSQLAdminClient_GetLocation() { |
| 94 |
ctx := context.Background() |
| 95 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 96 |
// It will require modifications to work: |
| 97 |
// - It may require correct/in-range values for request initialization. |
| 98 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 99 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 100 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 101 |
if err != nil { |
| 102 |
// TODO: Handle error. |
| 103 |
} |
| 104 |
defer c.Close() |
| 105 |
|
| 106 |
req := &locationpb.GetLocationRequest{ |
| 107 |
// TODO: Fill request struct fields. |
| 108 |
// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. |
| 109 |
} |
| 110 |
resp, err := c.GetLocation(ctx, req) |
| 111 |
if err != nil { |
| 112 |
// TODO: Handle error. |
| 113 |
} |
| 114 |
// TODO: Use resp. |
| 115 |
_ = resp |
| 116 |
} |
| 117 |
|
| 118 |
func ExampleAlloyDBCSQLAdminClient_ListLocations() { |
| 119 |
ctx := context.Background() |
| 120 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 121 |
// It will require modifications to work: |
| 122 |
// - It may require correct/in-range values for request initialization. |
| 123 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 124 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 125 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 126 |
if err != nil { |
| 127 |
// TODO: Handle error. |
| 128 |
} |
| 129 |
defer c.Close() |
| 130 |
|
| 131 |
req := &locationpb.ListLocationsRequest{ |
| 132 |
// TODO: Fill request struct fields. |
| 133 |
// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. |
| 134 |
} |
| 135 |
it := c.ListLocations(ctx, req) |
| 136 |
for { |
| 137 |
resp, err := it.Next() |
| 138 |
if err == iterator.Done { |
| 139 |
break |
| 140 |
} |
| 141 |
if err != nil { |
| 142 |
// TODO: Handle error. |
| 143 |
} |
| 144 |
// TODO: Use resp. |
| 145 |
_ = resp |
| 146 |
|
| 147 |
// If you need to access the underlying RPC response, |
| 148 |
// you can do so by casting the `Response` as below. |
| 149 |
// Otherwise, remove this line. Only populated after |
| 150 |
// first call to Next(). Not safe for concurrent access. |
| 151 |
_ = it.Response.(*locationpb.ListLocationsResponse) |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
func ExampleAlloyDBCSQLAdminClient_CancelOperation() { |
| 156 |
ctx := context.Background() |
| 157 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 158 |
// It will require modifications to work: |
| 159 |
// - It may require correct/in-range values for request initialization. |
| 160 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 161 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 162 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 163 |
if err != nil { |
| 164 |
// TODO: Handle error. |
| 165 |
} |
| 166 |
defer c.Close() |
| 167 |
|
| 168 |
req := &longrunningpb.CancelOperationRequest{ |
| 169 |
// TODO: Fill request struct fields. |
| 170 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. |
| 171 |
} |
| 172 |
err = c.CancelOperation(ctx, req) |
| 173 |
if err != nil { |
| 174 |
// TODO: Handle error. |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
func ExampleAlloyDBCSQLAdminClient_DeleteOperation() { |
| 179 |
ctx := context.Background() |
| 180 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 181 |
// It will require modifications to work: |
| 182 |
// - It may require correct/in-range values for request initialization. |
| 183 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 184 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 185 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 186 |
if err != nil { |
| 187 |
// TODO: Handle error. |
| 188 |
} |
| 189 |
defer c.Close() |
| 190 |
|
| 191 |
req := &longrunningpb.DeleteOperationRequest{ |
| 192 |
// TODO: Fill request struct fields. |
| 193 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. |
| 194 |
} |
| 195 |
err = c.DeleteOperation(ctx, req) |
| 196 |
if err != nil { |
| 197 |
// TODO: Handle error. |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
func ExampleAlloyDBCSQLAdminClient_GetOperation() { |
| 202 |
ctx := context.Background() |
| 203 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 204 |
// It will require modifications to work: |
| 205 |
// - It may require correct/in-range values for request initialization. |
| 206 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 207 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 208 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 209 |
if err != nil { |
| 210 |
// TODO: Handle error. |
| 211 |
} |
| 212 |
defer c.Close() |
| 213 |
|
| 214 |
req := &longrunningpb.GetOperationRequest{ |
| 215 |
// TODO: Fill request struct fields. |
| 216 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. |
| 217 |
} |
| 218 |
resp, err := c.GetOperation(ctx, req) |
| 219 |
if err != nil { |
| 220 |
// TODO: Handle error. |
| 221 |
} |
| 222 |
// TODO: Use resp. |
| 223 |
_ = resp |
| 224 |
} |
| 225 |
|
| 226 |
func ExampleAlloyDBCSQLAdminClient_ListOperations() { |
| 227 |
ctx := context.Background() |
| 228 |
// This snippet has been automatically generated and should be regarded as a code template only. |
| 229 |
// It will require modifications to work: |
| 230 |
// - It may require correct/in-range values for request initialization. |
| 231 |
// - It may require specifying regional endpoints when creating the service client as shown in: |
| 232 |
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options |
| 233 |
c, err := alloydb.NewAlloyDBCSQLAdminClient(ctx) |
| 234 |
if err != nil { |
| 235 |
// TODO: Handle error. |
| 236 |
} |
| 237 |
defer c.Close() |
| 238 |
|
| 239 |
req := &longrunningpb.ListOperationsRequest{ |
| 240 |
// TODO: Fill request struct fields. |
| 241 |
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. |
| 242 |
} |
| 243 |
it := c.ListOperations(ctx, req) |
| 244 |
for { |
| 245 |
resp, err := it.Next() |
| 246 |
if err == iterator.Done { |
| 247 |
break |
| 248 |
} |
| 249 |
if err != nil { |
| 250 |
// TODO: Handle error. |
| 251 |
} |
| 252 |
// TODO: Use resp. |
| 253 |
_ = resp |
| 254 |
|
| 255 |
// If you need to access the underlying RPC response, |
| 256 |
// you can do so by casting the `Response` as below. |
| 257 |
// Otherwise, remove this line. Only populated after |
| 258 |
// first call to Next(). Not safe for concurrent access. |
| 259 |
_ = it.Response.(*longrunningpb.ListOperationsResponse) |
| 260 |
} |
| 261 |
} |