Skip to content

Commit

Permalink
feat(gengapic): add in-line snippet comment to example.go (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzmo committed Sep 1, 2022
1 parent 6bb34d3 commit 88372c5
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/gengapic/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (g *generator) exampleInitClient(pkgName, servName string) {
p := g.printf

p("ctx := context.Background()")
p("// This snippet has been automatically generated and should be regarded as a code template only.")
p("// It will require modifications to work:")
p("// - It may require correct/in-range values for request initialization.")
p("// - It may require specifying regional endpoints when creating the service client as shown in:")
p("// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options")
p("c, err := %s.New%sClient(ctx)", pkgName, servName)
p("if err != nil {")
p(" // TODO: Handle error.")
Expand Down
45 changes: 45 additions & 0 deletions internal/gengapic/testdata/custom_op_example.want
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
func ExampleNewFooRESTClient() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -12,6 +17,11 @@ func ExampleNewFooRESTClient() {

func ExampleFooClient_GetEmptyThing() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -30,6 +40,11 @@ func ExampleFooClient_GetEmptyThing() {

func ExampleFooClient_GetOneThing() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -50,6 +65,11 @@ func ExampleFooClient_GetOneThing() {

func ExampleFooClient_GetBigThing() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -75,6 +95,11 @@ func ExampleFooClient_GetBigThing() {

func ExampleFooClient_GetManyThings() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -101,6 +126,11 @@ func ExampleFooClient_GetManyThings() {

func ExampleFooClient_BidiThings() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand Down Expand Up @@ -136,6 +166,11 @@ func ExampleFooClient_BidiThings() {

func ExampleFooClient_EmptyLRO() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -159,6 +194,11 @@ func ExampleFooClient_EmptyLRO() {

func ExampleFooClient_RespLRO() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand All @@ -184,6 +224,11 @@ func ExampleFooClient_RespLRO() {

func ExampleFooClient_CustomOp() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := Bar.NewFooRESTClient(ctx)
if err != nil {
// TODO: Handle error.
Expand Down
10 changes: 10 additions & 0 deletions internal/gengapic/testdata/doc_file.want
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand All @@ -40,6 +45,11 @@
// The following is an example of making an API call with the newly created client.
//
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
10 changes: 10 additions & 0 deletions internal/gengapic/testdata/doc_file_alpha.want
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand All @@ -42,6 +47,11 @@
// The following is an example of making an API call with the newly created client.
//
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
5 changes: 5 additions & 0 deletions internal/gengapic/testdata/doc_file_alpha_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
10 changes: 10 additions & 0 deletions internal/gengapic/testdata/doc_file_beta.want
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand All @@ -42,6 +47,11 @@
// The following is an example of making an API call with the newly created client.
//
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
5 changes: 5 additions & 0 deletions internal/gengapic/testdata/doc_file_beta_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
5 changes: 5 additions & 0 deletions internal/gengapic/testdata/doc_file_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
//
// To get started with this package, create a client.
// ctx := context.Background()
// // This snippet has been automatically generated and should be regarded as a code template only.
// // It will require modifications to work:
// // - It may require correct/in-range values for request initialization.
// // - It may require specifying regional endpoints when creating the service client as shown in:
// // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
// c, err := awesome.NewFooClient(ctx)
// if err != nil {
// // TODO: Handle error.
Expand Down
Loading

0 comments on commit 88372c5

Please sign in to comment.