Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gengapic): add in-line snippet comment to example.go #1120

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p("// This snippet has been automatically generated and should be regarded as a code template only.")
p("// This code has been automatically generated and should be regarded as a template only.")

Make this more vague I think. This also will appear as godoc examples and the term snippet has no meaning there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the exact wording is spec'd, I think it's better to stick with it.

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