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

Add new "quickstart" samples. #131

Merged
merged 7 commits into from
Apr 11, 2017
Merged

Add new "quickstart" samples. #131

merged 7 commits into from
Apr 11, 2017

Conversation

jmdobry
Copy link
Member

@jmdobry jmdobry commented Oct 5, 2016

These are intended to be simple examples that explicitly show:

  • Importing the client library
  • Instantiating a client
  • Making a single API call
  • Printing the result

Note: This is my first attempt at writing Go, please be nice 😄

Note 2: The variable names, region tags, structure of the sample, etc. were all carefully chosen and currently match the "quickstart" samples for other languages (linked to below), so this is how we'd like the samples to look. But, if I've done something glaringly non-idiomatic then let's fix that.

Note 3: I'd love to have provided tests, but can you (golang-samples maintainers) help out with the tests? I'm off writing these samples in 6 other languages... I ran all of the samples locally to make sure they work.

Products covered:

For reference, see the corresponding samples in other languages:

Thanks!

@broady
Copy link
Contributor

broady commented Oct 5, 2016

I'm wondering why these snippets are to live in this repo and not as top-level godoc examples in the library code itself. This comment is likely specific to Go, and something we're having ongoing discussions with @rakyll and the eng team (including @jba).

A few high level comments:

  1. Move each one into a *_quickstart directory. In Go, each package is a directory. The filename is not relevant. For example, the Vision quickstart might be in vision/vision_quickstart.
  2. Add a package-level doc to each file. For example, vision would be // Sample vision_quickstart is a ....
  3. Run gofmt over each file.
  4. projectId should be projectID
  5. There is no "instantiation" in Go. Use "Create". But more generally, these comments don't seem very useful. We can discuss that off-thread, though. I understand you put a lot of thought into it already.
  6. // Imports the Google Cloud client library should be more specific, and not use the name "library". // Imports the Google Cloud Datastore client package or similar.
  7. No need for region tags if the entire file is being included.

I will comment on specific code/files once the above is done.

@jmdobry
Copy link
Member Author

jmdobry commented Oct 5, 2016

I'm wondering why these snippets are to live in this repo and not as top-level godoc examples in the library code itself. This is specific to Go, and something we're having ongoing discussions with @rakyll and the eng team (including @jba).

Whether you eventually want https://cloud.google.com to source samples from google-cloud-go is fine with me. It was just easier for me to submit the PR to this repo.

I'll work through the rest of your comments.

@broady
Copy link
Contributor

broady commented Oct 5, 2016

Yeah, perfect. Don't worry too much about the directory name, then.

If you prefer, I (or Jaana) can also just take it from here and put it in the appropriate place, and add you as a reviewer.

@jmdobry
Copy link
Member Author

jmdobry commented Oct 5, 2016

Move each one into a *_quickstart directory. In Go, each package is a directory. The filename is not relevant. For example, the Vision quickstart might be in vision/vision_quickstart.

Done

Add a package-level doc to each file. For example, vision would be // Sample vision_quickstart is a ....

Done

Run gofmt over each file.

Done

projectId should be projectID

Done

There is no "instantiation" in Go. Use "Create".

Done

// Imports the Google Cloud client library should be more specific, and not use the name "library". // Imports the Google Cloud Datastore client package or similar.

Done

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot
Copy link

CLAs look good, thanks!

@jmdobry jmdobry force-pushed the quickstarts branch 2 times, most recently from bc64334 to 2dcff97 Compare November 17, 2016 19:07
"golang.org/x/net/context"
"log"

// Imports the Google Cloud Datastore client package
Copy link
Contributor

Choose a reason for hiding this comment

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

We follow the typical Go comment style to keep these types of guidance comments as proper sentences.

// Imports the Google Cloud Datastore client package.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// license that can be found in the LICENSE file.

// [START bigquery_quickstart]
// Sample bigquery_quickstart creates a Google BigQuery dataset.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not very common to name packages with an underscore in Go. Can we call name these as bigquery-quickstart?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// The name for the new dataset
datasetName := "my_new_dataset"

// Prepares the new dataset
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should just say "Create a dataset instance." if we need to explain the line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

log.Fatalf("Failed to create dataset: %v", err)
}

fmt.Printf("Dataset %v created", dataset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Dataset doesn't have a nice Stringer. I'd just leave this as fmt.Println("Dataset created.")

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

log.Fatalf("Failed to create dataset: %v", err)
}

fmt.Printf("Dataset %v created", dataset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing new line at the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

// [START vision_quickstart]
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto fofr thte name

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


import (
"fmt"
"golang.org/x/net/context"
Copy link
Contributor

Choose a reason for hiding this comment

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

move context to another group.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}

// The name of the image file to annotate
fileName := "vision/testdata/cat.jpg"
Copy link
Contributor

Choose a reason for hiding this comment

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

s/fileName/filename. See https://en.wikipedia.org/wiki/Filename.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

log.Fatalf("Failed to create image: %v", err)
}

labels, err := client.DetectLabels(ctx, image, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing error check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


labels, err := client.DetectLabels(ctx, image, 10)

fmt.Printf("Labels:\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

or fmt.Println("Labels:")

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

@jmdobry jmdobry self-assigned this Jan 17, 2017
@jmdobry jmdobry force-pushed the quickstarts branch 3 times, most recently from e0fd9d8 to e34cb4b Compare January 25, 2017 23:29
@broady
Copy link
Contributor

broady commented Mar 1, 2017

@waprin moving to e-mail

The prefix instructions for queries are incorrect in the Google Cloud Storage sample according to my testing. The `/` belongs at the end of the prefix to look up files in a directory, not at the beginning.
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@broady broady merged commit 18c1db4 into master Apr 11, 2017
@broady broady deleted the quickstarts branch April 11, 2017 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants