Vendor dependencies for GCS

This commit is contained in:
Alexander Neumann
2017-08-05 20:17:15 +02:00
parent ba75a3884c
commit 8ca6a9a240
1228 changed files with 1769186 additions and 1 deletions

48
vendor/cloud.google.com/go/internal/readme/Makefile generated vendored Normal file
View File

@@ -0,0 +1,48 @@
# Rebuild the README.md file at repo root by inserting code samples
# from compilable go files.
SHELL=/bin/bash
GOCLOUD_HOME=$(GOPATH)/src/cloud.google.com/go
README=$(GOCLOUD_HOME)/README.md
.PHONY: readme test test-good test-bad-go test-bad-md
readme:
@tmp=$$(mktemp); \
awk -f snipmd.awk snippets.go $(README) > $$tmp; \
mv $$tmp $(README)
diff:
diff $(README) <(awk -f snipmd.awk snippets.go $(README))
test: test-good test-bad-go test-bad-md
@echo PASS
test-good:
@echo testdata/good.md
@cd testdata >& /dev/null; \
diff -u want.md <(awk -f ../snipmd.awk snips.go good.md)
@echo "testdata/want.md (round trip)"
@cd testdata >& /dev/null; \
diff -u want.md <(awk -f ../snipmd.awk snips.go want.md)
test-bad-go:
@for f in testdata/bad-*.go; do \
echo $$f; \
if awk -f snipmd.awk $$f >& /dev/null; then \
echo "$f succeeded, want failure"; \
exit 1; \
fi; \
done
test-bad-md:
@for f in testdata/bad-*.md; do \
echo $$f; \
if awk -f snipmd.awk testdata/snips.go $$f >& /dev/null; then \
echo "$f succeeded, want failure"; \
exit 1; \
fi; \
done

123
vendor/cloud.google.com/go/internal/readme/snipmd.awk generated vendored Normal file
View File

@@ -0,0 +1,123 @@
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# snipmd inserts code snippets from Go source files into a markdown file.
#
# Call with one or more .go files and a .md file:
#
# awk -f snipmd.awk foo.go bar.go template.md
#
# In the Go files, start a snippet with
# //[ NAME
# and end it with
# //]
#
# In the markdown, write
# [snip]:# NAME
# to insert the snippet NAME just below that line.
# If there is already a code block after the [snip]:# line, it will be
# replaced, so a previous output can be used as input.
#
# The following transformations are made to the Go code:
# - The first tab of each line is removed.
# - Trailing blank lines are removed.
# - `ELLIPSIS` and `_ = ELLIPSIS` are replaced by `...`
/^[ \t]*\/\/\[/ { # start snippet in Go file
if (inGo()) {
if ($2 == "") {
die("missing snippet name")
}
curSnip = $2
next
}
}
/^[ \t]*\/\/]/ { # end snippet in Go file
if (inGo()) {
if (curSnip != "") {
# Remove all but one trailing newline.
gsub(/\n+$/, "\n", snips[curSnip])
curSnip = ""
next
} else {
die("//] without corresponding //[")
}
}
}
ENDFILE {
if (curSnip != "") {
die("unclosed snippet: " curSnip)
}
}
# Skip code blocks in the input that immediately follow [snip]:# lines,
# because we just inserted the snippet. Supports round-tripping.
/^```go$/,/^```$/ {
if (inMarkdown() && afterSnip) {
next
}
}
# Matches every line.
{
if (curSnip != "") {
line = $0
# Remove initial tab, if any.
if (line ~ /^\t/) {
line = substr(line, 2)
}
# Replace ELLIPSIS.
gsub(/_ = ELLIPSIS/, "...", line)
gsub(/ELLIPSIS/, "...", line)
snips[curSnip] = snips[curSnip] line "\n"
} else if (inMarkdown()) {
afterSnip = 0
# Copy .md to output.
print
}
}
$1 ~ /\[snip\]:#/ { # Snippet marker in .md file.
if (inMarkdown()) {
# We expect '[snip]:#' to be followed by '(NAME)'
if ($2 !~ /\(.*\)/) {
die("bad snip spec: " $0)
}
name = substr($2, 2, length($2)-2)
if (snips[name] == "") {
die("no snippet named " name)
}
printf("```go\n%s```\n", snips[name])
afterSnip = 1
}
}
function inMarkdown() {
return match(FILENAME, /\.md$/)
}
function inGo() {
return match(FILENAME, /\.go$/)
}
function die(msg) {
printf("%s:%d: %s\n", FILENAME, FNR, msg) > "/dev/stderr"
exit 1
}

241
vendor/cloud.google.com/go/internal/readme/snippets.go generated vendored Normal file
View File

@@ -0,0 +1,241 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file holds samples that are embedded into README.md.
// This file has to compile, but need not execute.
// If it fails to compile, fix it, then run `make` to regenerate README.md.
package readme
import (
"fmt"
"io/ioutil"
"log"
"time"
"cloud.google.com/go/bigquery"
"cloud.google.com/go/datastore"
"cloud.google.com/go/logging"
"cloud.google.com/go/pubsub"
"cloud.google.com/go/spanner"
"cloud.google.com/go/storage"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
var ctx context.Context
const END = 0
func auth() {
//[ auth
client, err := storage.NewClient(ctx)
//]
_ = client
_ = err
}
func auth2() {
//[ auth-JSON
client, err := storage.NewClient(ctx, option.WithServiceAccountFile("path/to/keyfile.json"))
//]
_ = client
_ = err
}
func auth3() {
var ELLIPSIS oauth2.TokenSource
//[ auth-ts
tokenSource := ELLIPSIS
client, err := storage.NewClient(ctx, option.WithTokenSource(tokenSource))
//]
_ = client
_ = err
}
func datastoreSnippets() {
//[ datastore-1
client, err := datastore.NewClient(ctx, "my-project-id")
if err != nil {
log.Fatal(err)
}
//]
//[ datastore-2
type Post struct {
Title string
Body string `datastore:",noindex"`
PublishedAt time.Time
}
keys := []*datastore.Key{
datastore.NameKey("Post", "post1", nil),
datastore.NameKey("Post", "post2", nil),
}
posts := []*Post{
{Title: "Post 1", Body: "...", PublishedAt: time.Now()},
{Title: "Post 2", Body: "...", PublishedAt: time.Now()},
}
if _, err := client.PutMulti(ctx, keys, posts); err != nil {
log.Fatal(err)
}
//]
}
func storageSnippets() {
//[ storage-1
client, err := storage.NewClient(ctx)
if err != nil {
log.Fatal(err)
}
//]
//[ storage-2
// Read the object1 from bucket.
rc, err := client.Bucket("bucket").Object("object1").NewReader(ctx)
if err != nil {
log.Fatal(err)
}
defer rc.Close()
body, err := ioutil.ReadAll(rc)
if err != nil {
log.Fatal(err)
}
//]
_ = body
}
func pubsubSnippets() {
//[ pubsub-1
client, err := pubsub.NewClient(ctx, "project-id")
if err != nil {
log.Fatal(err)
}
//]
const ELLIPSIS = 0
//[ pubsub-2
// Publish "hello world" on topic1.
topic := client.Topic("topic1")
res := topic.Publish(ctx, &pubsub.Message{
Data: []byte("hello world"),
})
// The publish happens asynchronously.
// Later, you can get the result from res:
_ = ELLIPSIS
msgID, err := res.Get(ctx)
if err != nil {
log.Fatal(err)
}
// Use a callback to receive messages via subscription1.
sub := client.Subscription("subscription1")
err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
fmt.Println(m.Data)
m.Ack() // Acknowledge that we've consumed the message.
})
if err != nil {
log.Println(err)
}
//]
_ = msgID
}
func bqSnippets() {
//[ bq-1
c, err := bigquery.NewClient(ctx, "my-project-ID")
if err != nil {
// TODO: Handle error.
}
//]
//[ bq-2
// Construct a query.
q := c.Query(`
SELECT year, SUM(number)
FROM [bigquery-public-data:usa_names.usa_1910_2013]
WHERE name = "William"
GROUP BY year
ORDER BY year
`)
// Execute the query.
it, err := q.Read(ctx)
if err != nil {
// TODO: Handle error.
}
// Iterate through the results.
for {
var values []bigquery.Value
err := it.Next(&values)
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
fmt.Println(values)
}
//]
}
func loggingSnippets() {
//[ logging-1
ctx := context.Background()
client, err := logging.NewClient(ctx, "my-project")
if err != nil {
// TODO: Handle error.
}
//]
//[ logging-2
logger := client.Logger("my-log")
logger.Log(logging.Entry{Payload: "something happened!"})
//]
//[ logging-3
err = client.Close()
if err != nil {
// TODO: Handle error.
}
//]
}
func spannerSnippets() {
//[ spanner-1
client, err := spanner.NewClient(ctx, "projects/P/instances/I/databases/D")
if err != nil {
log.Fatal(err)
}
//]
//[ spanner-2
// Simple Reads And Writes
_, err = client.Apply(ctx, []*spanner.Mutation{
spanner.Insert("Users",
[]string{"name", "email"},
[]interface{}{"alice", "a@example.com"})})
if err != nil {
log.Fatal(err)
}
row, err := client.Single().ReadRow(ctx, "Users",
spanner.Key{"alice"}, []string{"email"})
if err != nil {
log.Fatal(err)
}
//]
_ = row
}

View File

@@ -0,0 +1,23 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package readme
import "fmt"
func f() {
//[
fmt.Println()
//]
}

View File

@@ -0,0 +1,19 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package readme
func f() {
//]
}

View File

@@ -0,0 +1,2 @@
[snip]:# (unknown)

View File

@@ -0,0 +1 @@
[snip]:# missing-parens

View File

@@ -0,0 +1,21 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package readme
// unclosed snippet
func f() {
//[ X
}

View File

@@ -0,0 +1,18 @@
This template is for testing snipmd.awk.
Put the first snippet here.
[snip]:# (first)
And now the second.
[snip]:# (second)
A top-level snippet.
[snip]:# (top-level)
```go
// A code block that is not included.
```
And we're done.

View File

@@ -0,0 +1,39 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package readme
import (
"errors"
"fmt"
)
func f() {
ELLIPSIS := 3
//[ first
fmt.Println("hello")
x := ELLIPSIS
//]
//[ second
if x > 2 {
_ = ELLIPSIS
}
//]
}
//[ top-level
var ErrBad = errors.New("bad")
//]

View File

@@ -0,0 +1,30 @@
This template is for testing snipmd.awk.
Put the first snippet here.
[snip]:# (first)
```go
fmt.Println("hello")
x := ...
```
And now the second.
[snip]:# (second)
```go
if x > 2 {
...
}
```
A top-level snippet.
[snip]:# (top-level)
```go
var ErrBad = errors.New("bad")
```
```go
// A code block that is not included.
```
And we're done.