Skip to content

Instantly share code, notes, and snippets.

@najeira
Created August 15, 2014 03:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save najeira/280c347ecb6bd9f2e680 to your computer and use it in GitHub Desktop.
Save najeira/280c347ecb6bd9f2e680 to your computer and use it in GitHub Desktop.
Golang BigQuery example
package main
import (
bigquery "code.google.com/p/google-api-go-client/bigquery/v2"
"code.google.com/p/goauth2/oauth/jwt"
"encoding/json"
"fmt"
)
func main() {
iss := "yourname@developer.gserviceaccount.com"
scope := bigquery.BigqueryScope
pem := `-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----`
token := jwt.NewToken(iss, scope, []byte(pem))
transport, _ := jwt.NewTransport(token)
client := transport.Client()
bq, _ := bigquery.New(client)
call := bq.Tabledata.List("projectid", "dataset", "table")
call.MaxResults(10)
list, _ := call.Do()
buf, _ := json.Marshal(list)
fmt.Println(string(buf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment