Files
fn-serverless/vendor/google.golang.org/api/examples/books.go
Reed Allman 9eaf824398 add jaeger support, link hot container & req span (#840)
* add jaeger support, link hot container & req span

* adds jaeger support now with FN_JAEGER_URL, there's a simple tutorial in the
operating/metrics.md file now and it's pretty easy to get up and running.
* links a hot request span to a hot container span. when we change this to
sample at a lower ratio we'll need to finagle the hot container span to always
sample or something, otherwise we'll hide that info. at least, since we're
sampling at 100% for now if this is flipped on, can see freeze/unfreeze etc.
if they hit. this is useful for debugging. note that zipkin's exporter does
not follow the link at all, hence jaeger... and they're backed by the Cloud
Empire now (CNCF) so we'll probably use it anyway.

* vendor: add thrift for jaeger
2018-03-13 15:57:12 -07:00

78 lines
2.1 KiB
Go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"strings"
books "google.golang.org/api/books/v1"
"google.golang.org/api/googleapi"
)
func init() {
registerDemo("books", books.BooksScope, booksMain)
}
// booksMain is an example that demonstrates calling the Books API.
//
// Example usage:
// go build -o go-api-demo *.go
// go-api-demo -clientid="my-clientid" -secret="my-secret" books
func booksMain(client *http.Client, argv []string) {
if len(argv) != 0 {
fmt.Fprintln(os.Stderr, "Usage: books")
return
}
svc, err := books.New(client)
if err != nil {
log.Fatalf("Unable to create Books service: %v", err)
}
bs, err := svc.Mylibrary.Bookshelves.List().Do()
if err != nil {
log.Fatalf("Unable to retrieve mylibrary bookshelves: %v", err)
}
if len(bs.Items) == 0 {
log.Fatal("You have no bookshelves to explore.")
}
for _, b := range bs.Items {
// Note that sometimes VolumeCount is not populated, so it may erroneously say '0'.
log.Printf("You have %v books on bookshelf %q:", b.VolumeCount, b.Title)
// List the volumes on this shelf.
vol, err := svc.Mylibrary.Bookshelves.Volumes.List(strconv.FormatInt(b.Id, 10)).Do()
if err != nil {
log.Fatalf("Unable to retrieve mylibrary bookshelf volumes: %v", err)
}
for _, v := range vol.Items {
var info struct {
Text bool `json:"text"`
Image bool `json:"image"`
}
// Parse the additional fields, but ignore errors, as the information is not critical.
googleapi.ConvertVariant(v.VolumeInfo.ReadingModes.(map[string]interface{}), &info)
var s []string
if info.Text {
s = append(s, "text")
}
if info.Image {
s = append(s, "image")
}
extra := fmt.Sprintf("; formats: %v", s)
if v.VolumeInfo.ImageLinks != nil {
extra += fmt.Sprintf("; thumbnail: %v", v.VolumeInfo.ImageLinks.Thumbnail)
}
log.Printf(" %q by %v%v", v.VolumeInfo.Title, strings.Join(v.VolumeInfo.Authors, ", "), extra)
}
}
}