-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START bigquery_quickstart] | ||
// Sample bigquery_quickstart creates a Google BigQuery dataset. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud Datastore client package | ||
"cloud.google.com/go/bigquery" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectID := "YOUR_PROJECT_ID" | ||
|
||
// Creates a client | ||
client, err := bigquery.NewClient(ctx, projectID) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The name for the new dataset | ||
datasetName := "my_new_dataset" | ||
|
||
// Prepares the new dataset | ||
dataset := client.Dataset(datasetName) | ||
|
||
// Creates the dataset | ||
if err := dataset.Create(ctx); err != nil { | ||
log.Fatalf("Failed to create dataset: %v", err) | ||
} | ||
|
||
fmt.Printf("Dataset %v created", dataset) | ||
} | ||
|
||
// [END bigquery_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START datastore_quickstart] | ||
// Sample datastore_quickstart fetches an entity from Google Cloud Datastore. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud Datastore client package | ||
"cloud.google.com/go/datastore" | ||
) | ||
|
||
type Entity struct { | ||
Value string | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectID := "YOUR_PROJECT_ID" | ||
|
||
// Creates a client | ||
client, err := datastore.NewClient(ctx, projectID) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The kind of the entity to retrieve | ||
kind := "Person" | ||
// The name/ID of the entity to retrieve | ||
name := "Bob" | ||
// The Datastore key for the entity | ||
key := datastore.NewKey(ctx, kind, name, 0, nil) | ||
|
||
entity := new(Entity) | ||
|
||
// Retrieves the entity | ||
if err := client.Get(ctx, key, entity); err != nil { | ||
log.Fatalf("Failed to get entity: %v", err) | ||
} | ||
|
||
fmt.Printf("Fetched entity: %v", key.String()) | ||
} | ||
|
||
// [END datastore_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START logging_quickstart] | ||
// Sample logging_quickstart writes a log entry to Stackdriver Logging. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Stackdriver Logging client package | ||
"cloud.google.com/go/logging" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectID := "YOUR_PROJECT_ID" | ||
|
||
// Creates a client | ||
client, err := logging.NewClient(ctx, projectID) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The name of the log to write to | ||
logName := "my-log" | ||
|
||
// Selects the log to write to | ||
logger := client.Logger(logName) | ||
|
||
// The data to log | ||
text := "Hello, world!" | ||
|
||
// Adds an entry to the log buffer | ||
logger.Log(logging.Entry{Payload: text}) | ||
|
||
// Closes the client and flushes the buffer to the Stackdriver Logging service | ||
err = client.Close() | ||
if err != nil { | ||
log.Fatalf("Failed to close client: %v", err) | ||
} | ||
|
||
fmt.Printf("Logged: %v", text) | ||
} | ||
|
||
// [END logging_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START pubsub_quickstart] | ||
// Sample pubsub_quickstart creates a Google Cloud Pub/Sub topic. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud Pub/Sub client package | ||
"cloud.google.com/go/pubsub" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectID := "YOUR_PROJECT_ID" | ||
|
||
// Creates a client | ||
client, err := pubsub.NewClient(ctx, projectID) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The name for the new topic | ||
topicName := "my-new-topic" | ||
|
||
// Creates the new topic | ||
topic, err := client.CreateTopic(ctx, topicName) | ||
if err != nil { | ||
log.Fatalf("Failed to create topic: %v", err) | ||
} | ||
|
||
fmt.Printf("Topic %v created.", topic) | ||
} | ||
|
||
// [END pubsub_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START storage_quickstart] | ||
// Sample storage_quickstart creates a Google Cloud Storage bucket. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud Storage client package | ||
"cloud.google.com/go/storage" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectID := "YOUR_PROJECT_ID" | ||
|
||
// Creates a client | ||
client, err := storage.NewClient(ctx) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The name for the new bucket | ||
bucketName := "my-new-bucket" | ||
|
||
// Prepares a new bucket | ||
bucket := client.Bucket(bucketName) | ||
|
||
// Creates the new bucket | ||
if err := bucket.Create(ctx, projectID, nil); err != nil { | ||
log.Fatalf("Failed to create bucket: %v", err) | ||
} | ||
|
||
fmt.Printf("Bucket %v created.", bucketName) | ||
} | ||
|
||
// [END storage_quickstart] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2016 Google Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
// [START vision_quickstart] | ||
// Sample vision_quickstart uses the Google Cloud Vision API to label an image. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
"os" | ||
|
||
// Imports the Google Cloud Vision API client package | ||
"cloud.google.com/go/vision" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Creates a client | ||
client, err := vision.NewClient(ctx) | ||
if err != nil { | ||
log.Fatalf("Failed to create client: %v", err) | ||
} | ||
|
||
// The name of the image file to annotate | ||
fileName := "vision/testdata/cat.jpg" | ||
|
||
file, err := os.Open(fileName) | ||
if err != nil { | ||
log.Fatalf("Failed to read file: %v", err) | ||
} | ||
defer file.Close() | ||
image, err := vision.NewImageFromReader(file) | ||
if err != nil { | ||
log.Fatalf("Failed to create image: %v", err) | ||
} | ||
|
||
labels, err := client.DetectLabels(ctx, image, 10) | ||
|
||
fmt.Printf("Labels:\n") | ||
for _, label := range labels { | ||
fmt.Println(label.Description) | ||
} | ||
} | ||
|
||
// [END vision_quickstart] |