...

Source file src/cloud.google.com/go/bigquery/datatransfer/apiv1/data_transfer_client_example_test.go

Documentation: cloud.google.com/go/bigquery/datatransfer/apiv1

     1  // Copyright 2024 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 datatransfer_test
    18  
    19  import (
    20  	"context"
    21  
    22  	datatransfer "cloud.google.com/go/bigquery/datatransfer/apiv1"
    23  	datatransferpb "cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb"
    24  	"google.golang.org/api/iterator"
    25  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    26  )
    27  
    28  func ExampleNewClient() {
    29  	ctx := context.Background()
    30  	// This snippet has been automatically generated and should be regarded as a code template only.
    31  	// It will require modifications to work:
    32  	// - It may require correct/in-range values for request initialization.
    33  	// - It may require specifying regional endpoints when creating the service client as shown in:
    34  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    35  	c, err := datatransfer.NewClient(ctx)
    36  	if err != nil {
    37  		// TODO: Handle error.
    38  	}
    39  	defer c.Close()
    40  
    41  	// TODO: Use client.
    42  	_ = c
    43  }
    44  
    45  func ExampleNewRESTClient() {
    46  	ctx := context.Background()
    47  	// This snippet has been automatically generated and should be regarded as a code template only.
    48  	// It will require modifications to work:
    49  	// - It may require correct/in-range values for request initialization.
    50  	// - It may require specifying regional endpoints when creating the service client as shown in:
    51  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    52  	c, err := datatransfer.NewRESTClient(ctx)
    53  	if err != nil {
    54  		// TODO: Handle error.
    55  	}
    56  	defer c.Close()
    57  
    58  	// TODO: Use client.
    59  	_ = c
    60  }
    61  
    62  func ExampleClient_CheckValidCreds() {
    63  	ctx := context.Background()
    64  	// This snippet has been automatically generated and should be regarded as a code template only.
    65  	// It will require modifications to work:
    66  	// - It may require correct/in-range values for request initialization.
    67  	// - It may require specifying regional endpoints when creating the service client as shown in:
    68  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    69  	c, err := datatransfer.NewClient(ctx)
    70  	if err != nil {
    71  		// TODO: Handle error.
    72  	}
    73  	defer c.Close()
    74  
    75  	req := &datatransferpb.CheckValidCredsRequest{
    76  		// TODO: Fill request struct fields.
    77  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#CheckValidCredsRequest.
    78  	}
    79  	resp, err := c.CheckValidCreds(ctx, req)
    80  	if err != nil {
    81  		// TODO: Handle error.
    82  	}
    83  	// TODO: Use resp.
    84  	_ = resp
    85  }
    86  
    87  func ExampleClient_CreateTransferConfig() {
    88  	ctx := context.Background()
    89  	// This snippet has been automatically generated and should be regarded as a code template only.
    90  	// It will require modifications to work:
    91  	// - It may require correct/in-range values for request initialization.
    92  	// - It may require specifying regional endpoints when creating the service client as shown in:
    93  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    94  	c, err := datatransfer.NewClient(ctx)
    95  	if err != nil {
    96  		// TODO: Handle error.
    97  	}
    98  	defer c.Close()
    99  
   100  	req := &datatransferpb.CreateTransferConfigRequest{
   101  		// TODO: Fill request struct fields.
   102  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#CreateTransferConfigRequest.
   103  	}
   104  	resp, err := c.CreateTransferConfig(ctx, req)
   105  	if err != nil {
   106  		// TODO: Handle error.
   107  	}
   108  	// TODO: Use resp.
   109  	_ = resp
   110  }
   111  
   112  func ExampleClient_DeleteTransferConfig() {
   113  	ctx := context.Background()
   114  	// This snippet has been automatically generated and should be regarded as a code template only.
   115  	// It will require modifications to work:
   116  	// - It may require correct/in-range values for request initialization.
   117  	// - It may require specifying regional endpoints when creating the service client as shown in:
   118  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   119  	c, err := datatransfer.NewClient(ctx)
   120  	if err != nil {
   121  		// TODO: Handle error.
   122  	}
   123  	defer c.Close()
   124  
   125  	req := &datatransferpb.DeleteTransferConfigRequest{
   126  		// TODO: Fill request struct fields.
   127  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#DeleteTransferConfigRequest.
   128  	}
   129  	err = c.DeleteTransferConfig(ctx, req)
   130  	if err != nil {
   131  		// TODO: Handle error.
   132  	}
   133  }
   134  
   135  func ExampleClient_DeleteTransferRun() {
   136  	ctx := context.Background()
   137  	// This snippet has been automatically generated and should be regarded as a code template only.
   138  	// It will require modifications to work:
   139  	// - It may require correct/in-range values for request initialization.
   140  	// - It may require specifying regional endpoints when creating the service client as shown in:
   141  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   142  	c, err := datatransfer.NewClient(ctx)
   143  	if err != nil {
   144  		// TODO: Handle error.
   145  	}
   146  	defer c.Close()
   147  
   148  	req := &datatransferpb.DeleteTransferRunRequest{
   149  		// TODO: Fill request struct fields.
   150  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#DeleteTransferRunRequest.
   151  	}
   152  	err = c.DeleteTransferRun(ctx, req)
   153  	if err != nil {
   154  		// TODO: Handle error.
   155  	}
   156  }
   157  
   158  func ExampleClient_EnrollDataSources() {
   159  	ctx := context.Background()
   160  	// This snippet has been automatically generated and should be regarded as a code template only.
   161  	// It will require modifications to work:
   162  	// - It may require correct/in-range values for request initialization.
   163  	// - It may require specifying regional endpoints when creating the service client as shown in:
   164  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   165  	c, err := datatransfer.NewClient(ctx)
   166  	if err != nil {
   167  		// TODO: Handle error.
   168  	}
   169  	defer c.Close()
   170  
   171  	req := &datatransferpb.EnrollDataSourcesRequest{
   172  		// TODO: Fill request struct fields.
   173  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#EnrollDataSourcesRequest.
   174  	}
   175  	err = c.EnrollDataSources(ctx, req)
   176  	if err != nil {
   177  		// TODO: Handle error.
   178  	}
   179  }
   180  
   181  func ExampleClient_GetDataSource() {
   182  	ctx := context.Background()
   183  	// This snippet has been automatically generated and should be regarded as a code template only.
   184  	// It will require modifications to work:
   185  	// - It may require correct/in-range values for request initialization.
   186  	// - It may require specifying regional endpoints when creating the service client as shown in:
   187  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   188  	c, err := datatransfer.NewClient(ctx)
   189  	if err != nil {
   190  		// TODO: Handle error.
   191  	}
   192  	defer c.Close()
   193  
   194  	req := &datatransferpb.GetDataSourceRequest{
   195  		// TODO: Fill request struct fields.
   196  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#GetDataSourceRequest.
   197  	}
   198  	resp, err := c.GetDataSource(ctx, req)
   199  	if err != nil {
   200  		// TODO: Handle error.
   201  	}
   202  	// TODO: Use resp.
   203  	_ = resp
   204  }
   205  
   206  func ExampleClient_GetTransferConfig() {
   207  	ctx := context.Background()
   208  	// This snippet has been automatically generated and should be regarded as a code template only.
   209  	// It will require modifications to work:
   210  	// - It may require correct/in-range values for request initialization.
   211  	// - It may require specifying regional endpoints when creating the service client as shown in:
   212  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   213  	c, err := datatransfer.NewClient(ctx)
   214  	if err != nil {
   215  		// TODO: Handle error.
   216  	}
   217  	defer c.Close()
   218  
   219  	req := &datatransferpb.GetTransferConfigRequest{
   220  		// TODO: Fill request struct fields.
   221  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#GetTransferConfigRequest.
   222  	}
   223  	resp, err := c.GetTransferConfig(ctx, req)
   224  	if err != nil {
   225  		// TODO: Handle error.
   226  	}
   227  	// TODO: Use resp.
   228  	_ = resp
   229  }
   230  
   231  func ExampleClient_GetTransferRun() {
   232  	ctx := context.Background()
   233  	// This snippet has been automatically generated and should be regarded as a code template only.
   234  	// It will require modifications to work:
   235  	// - It may require correct/in-range values for request initialization.
   236  	// - It may require specifying regional endpoints when creating the service client as shown in:
   237  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   238  	c, err := datatransfer.NewClient(ctx)
   239  	if err != nil {
   240  		// TODO: Handle error.
   241  	}
   242  	defer c.Close()
   243  
   244  	req := &datatransferpb.GetTransferRunRequest{
   245  		// TODO: Fill request struct fields.
   246  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#GetTransferRunRequest.
   247  	}
   248  	resp, err := c.GetTransferRun(ctx, req)
   249  	if err != nil {
   250  		// TODO: Handle error.
   251  	}
   252  	// TODO: Use resp.
   253  	_ = resp
   254  }
   255  
   256  func ExampleClient_ListDataSources() {
   257  	ctx := context.Background()
   258  	// This snippet has been automatically generated and should be regarded as a code template only.
   259  	// It will require modifications to work:
   260  	// - It may require correct/in-range values for request initialization.
   261  	// - It may require specifying regional endpoints when creating the service client as shown in:
   262  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   263  	c, err := datatransfer.NewClient(ctx)
   264  	if err != nil {
   265  		// TODO: Handle error.
   266  	}
   267  	defer c.Close()
   268  
   269  	req := &datatransferpb.ListDataSourcesRequest{
   270  		// TODO: Fill request struct fields.
   271  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#ListDataSourcesRequest.
   272  	}
   273  	it := c.ListDataSources(ctx, req)
   274  	for {
   275  		resp, err := it.Next()
   276  		if err == iterator.Done {
   277  			break
   278  		}
   279  		if err != nil {
   280  			// TODO: Handle error.
   281  		}
   282  		// TODO: Use resp.
   283  		_ = resp
   284  
   285  		// If you need to access the underlying RPC response,
   286  		// you can do so by casting the `Response` as below.
   287  		// Otherwise, remove this line. Only populated after
   288  		// first call to Next(). Not safe for concurrent access.
   289  		_ = it.Response.(*datatransferpb.ListDataSourcesResponse)
   290  	}
   291  }
   292  
   293  func ExampleClient_ListTransferConfigs() {
   294  	ctx := context.Background()
   295  	// This snippet has been automatically generated and should be regarded as a code template only.
   296  	// It will require modifications to work:
   297  	// - It may require correct/in-range values for request initialization.
   298  	// - It may require specifying regional endpoints when creating the service client as shown in:
   299  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   300  	c, err := datatransfer.NewClient(ctx)
   301  	if err != nil {
   302  		// TODO: Handle error.
   303  	}
   304  	defer c.Close()
   305  
   306  	req := &datatransferpb.ListTransferConfigsRequest{
   307  		// TODO: Fill request struct fields.
   308  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#ListTransferConfigsRequest.
   309  	}
   310  	it := c.ListTransferConfigs(ctx, req)
   311  	for {
   312  		resp, err := it.Next()
   313  		if err == iterator.Done {
   314  			break
   315  		}
   316  		if err != nil {
   317  			// TODO: Handle error.
   318  		}
   319  		// TODO: Use resp.
   320  		_ = resp
   321  
   322  		// If you need to access the underlying RPC response,
   323  		// you can do so by casting the `Response` as below.
   324  		// Otherwise, remove this line. Only populated after
   325  		// first call to Next(). Not safe for concurrent access.
   326  		_ = it.Response.(*datatransferpb.ListTransferConfigsResponse)
   327  	}
   328  }
   329  
   330  func ExampleClient_ListTransferLogs() {
   331  	ctx := context.Background()
   332  	// This snippet has been automatically generated and should be regarded as a code template only.
   333  	// It will require modifications to work:
   334  	// - It may require correct/in-range values for request initialization.
   335  	// - It may require specifying regional endpoints when creating the service client as shown in:
   336  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   337  	c, err := datatransfer.NewClient(ctx)
   338  	if err != nil {
   339  		// TODO: Handle error.
   340  	}
   341  	defer c.Close()
   342  
   343  	req := &datatransferpb.ListTransferLogsRequest{
   344  		// TODO: Fill request struct fields.
   345  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#ListTransferLogsRequest.
   346  	}
   347  	it := c.ListTransferLogs(ctx, req)
   348  	for {
   349  		resp, err := it.Next()
   350  		if err == iterator.Done {
   351  			break
   352  		}
   353  		if err != nil {
   354  			// TODO: Handle error.
   355  		}
   356  		// TODO: Use resp.
   357  		_ = resp
   358  
   359  		// If you need to access the underlying RPC response,
   360  		// you can do so by casting the `Response` as below.
   361  		// Otherwise, remove this line. Only populated after
   362  		// first call to Next(). Not safe for concurrent access.
   363  		_ = it.Response.(*datatransferpb.ListTransferLogsResponse)
   364  	}
   365  }
   366  
   367  func ExampleClient_ListTransferRuns() {
   368  	ctx := context.Background()
   369  	// This snippet has been automatically generated and should be regarded as a code template only.
   370  	// It will require modifications to work:
   371  	// - It may require correct/in-range values for request initialization.
   372  	// - It may require specifying regional endpoints when creating the service client as shown in:
   373  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   374  	c, err := datatransfer.NewClient(ctx)
   375  	if err != nil {
   376  		// TODO: Handle error.
   377  	}
   378  	defer c.Close()
   379  
   380  	req := &datatransferpb.ListTransferRunsRequest{
   381  		// TODO: Fill request struct fields.
   382  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#ListTransferRunsRequest.
   383  	}
   384  	it := c.ListTransferRuns(ctx, req)
   385  	for {
   386  		resp, err := it.Next()
   387  		if err == iterator.Done {
   388  			break
   389  		}
   390  		if err != nil {
   391  			// TODO: Handle error.
   392  		}
   393  		// TODO: Use resp.
   394  		_ = resp
   395  
   396  		// If you need to access the underlying RPC response,
   397  		// you can do so by casting the `Response` as below.
   398  		// Otherwise, remove this line. Only populated after
   399  		// first call to Next(). Not safe for concurrent access.
   400  		_ = it.Response.(*datatransferpb.ListTransferRunsResponse)
   401  	}
   402  }
   403  
   404  func ExampleClient_ScheduleTransferRuns() {
   405  	ctx := context.Background()
   406  	// This snippet has been automatically generated and should be regarded as a code template only.
   407  	// It will require modifications to work:
   408  	// - It may require correct/in-range values for request initialization.
   409  	// - It may require specifying regional endpoints when creating the service client as shown in:
   410  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   411  	c, err := datatransfer.NewClient(ctx)
   412  	if err != nil {
   413  		// TODO: Handle error.
   414  	}
   415  	defer c.Close()
   416  
   417  	req := &datatransferpb.ScheduleTransferRunsRequest{
   418  		// TODO: Fill request struct fields.
   419  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#ScheduleTransferRunsRequest.
   420  	}
   421  	resp, err := c.ScheduleTransferRuns(ctx, req)
   422  	if err != nil {
   423  		// TODO: Handle error.
   424  	}
   425  	// TODO: Use resp.
   426  	_ = resp
   427  }
   428  
   429  func ExampleClient_StartManualTransferRuns() {
   430  	ctx := context.Background()
   431  	// This snippet has been automatically generated and should be regarded as a code template only.
   432  	// It will require modifications to work:
   433  	// - It may require correct/in-range values for request initialization.
   434  	// - It may require specifying regional endpoints when creating the service client as shown in:
   435  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   436  	c, err := datatransfer.NewClient(ctx)
   437  	if err != nil {
   438  		// TODO: Handle error.
   439  	}
   440  	defer c.Close()
   441  
   442  	req := &datatransferpb.StartManualTransferRunsRequest{
   443  		// TODO: Fill request struct fields.
   444  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#StartManualTransferRunsRequest.
   445  	}
   446  	resp, err := c.StartManualTransferRuns(ctx, req)
   447  	if err != nil {
   448  		// TODO: Handle error.
   449  	}
   450  	// TODO: Use resp.
   451  	_ = resp
   452  }
   453  
   454  func ExampleClient_UnenrollDataSources() {
   455  	ctx := context.Background()
   456  	// This snippet has been automatically generated and should be regarded as a code template only.
   457  	// It will require modifications to work:
   458  	// - It may require correct/in-range values for request initialization.
   459  	// - It may require specifying regional endpoints when creating the service client as shown in:
   460  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   461  	c, err := datatransfer.NewClient(ctx)
   462  	if err != nil {
   463  		// TODO: Handle error.
   464  	}
   465  	defer c.Close()
   466  
   467  	req := &datatransferpb.UnenrollDataSourcesRequest{
   468  		// TODO: Fill request struct fields.
   469  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#UnenrollDataSourcesRequest.
   470  	}
   471  	err = c.UnenrollDataSources(ctx, req)
   472  	if err != nil {
   473  		// TODO: Handle error.
   474  	}
   475  }
   476  
   477  func ExampleClient_UpdateTransferConfig() {
   478  	ctx := context.Background()
   479  	// This snippet has been automatically generated and should be regarded as a code template only.
   480  	// It will require modifications to work:
   481  	// - It may require correct/in-range values for request initialization.
   482  	// - It may require specifying regional endpoints when creating the service client as shown in:
   483  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   484  	c, err := datatransfer.NewClient(ctx)
   485  	if err != nil {
   486  		// TODO: Handle error.
   487  	}
   488  	defer c.Close()
   489  
   490  	req := &datatransferpb.UpdateTransferConfigRequest{
   491  		// TODO: Fill request struct fields.
   492  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb#UpdateTransferConfigRequest.
   493  	}
   494  	resp, err := c.UpdateTransferConfig(ctx, req)
   495  	if err != nil {
   496  		// TODO: Handle error.
   497  	}
   498  	// TODO: Use resp.
   499  	_ = resp
   500  }
   501  
   502  func ExampleClient_GetLocation() {
   503  	ctx := context.Background()
   504  	// This snippet has been automatically generated and should be regarded as a code template only.
   505  	// It will require modifications to work:
   506  	// - It may require correct/in-range values for request initialization.
   507  	// - It may require specifying regional endpoints when creating the service client as shown in:
   508  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   509  	c, err := datatransfer.NewClient(ctx)
   510  	if err != nil {
   511  		// TODO: Handle error.
   512  	}
   513  	defer c.Close()
   514  
   515  	req := &locationpb.GetLocationRequest{
   516  		// TODO: Fill request struct fields.
   517  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   518  	}
   519  	resp, err := c.GetLocation(ctx, req)
   520  	if err != nil {
   521  		// TODO: Handle error.
   522  	}
   523  	// TODO: Use resp.
   524  	_ = resp
   525  }
   526  
   527  func ExampleClient_ListLocations() {
   528  	ctx := context.Background()
   529  	// This snippet has been automatically generated and should be regarded as a code template only.
   530  	// It will require modifications to work:
   531  	// - It may require correct/in-range values for request initialization.
   532  	// - It may require specifying regional endpoints when creating the service client as shown in:
   533  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   534  	c, err := datatransfer.NewClient(ctx)
   535  	if err != nil {
   536  		// TODO: Handle error.
   537  	}
   538  	defer c.Close()
   539  
   540  	req := &locationpb.ListLocationsRequest{
   541  		// TODO: Fill request struct fields.
   542  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   543  	}
   544  	it := c.ListLocations(ctx, req)
   545  	for {
   546  		resp, err := it.Next()
   547  		if err == iterator.Done {
   548  			break
   549  		}
   550  		if err != nil {
   551  			// TODO: Handle error.
   552  		}
   553  		// TODO: Use resp.
   554  		_ = resp
   555  
   556  		// If you need to access the underlying RPC response,
   557  		// you can do so by casting the `Response` as below.
   558  		// Otherwise, remove this line. Only populated after
   559  		// first call to Next(). Not safe for concurrent access.
   560  		_ = it.Response.(*locationpb.ListLocationsResponse)
   561  	}
   562  }
   563  

View as plain text