-
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
269 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,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 bigquery_quickstart] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud client library | ||
"cloud.google.com/go/bigquery" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectId := "YOUR_PROJECT_ID" | ||
|
||
// Instantiates 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,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 datastore_quickstart] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud client library | ||
"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" | ||
|
||
// Instantiates 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,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 logging_quickstart] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud client library | ||
"cloud.google.com/go/logging" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectId := "YOUR_PROJECT_ID" | ||
|
||
// Instantiates 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,40 @@ | ||
// 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] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud client library | ||
"cloud.google.com/go/pubsub" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectId := "YOUR_PROJECT_ID" | ||
|
||
// Instantiates 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,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 storage_quickstart] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
|
||
// Imports the Google Cloud client library | ||
"cloud.google.com/go/storage" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Your Google Cloud Platform project ID | ||
projectId := "YOUR_PROJECT_ID" | ||
|
||
// Instantiates 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,47 @@ | ||
// 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] | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/net/context" | ||
"log" | ||
"os" | ||
|
||
// Imports the Google Cloud client library | ||
"cloud.google.com/go/vision" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
// Instantiates 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 bigquery_quickstart] |