Skip to content

Instantly share code, notes, and snippets.

@swook
Last active December 20, 2015 08:49
Show Gist options
  • Save swook/6103244 to your computer and use it in GitHub Desktop.
Save swook/6103244 to your computer and use it in GitHub Desktop.
A short file to test mlab-ns2/gae/ns/rtt.BQInit.
package mlabns
import (
"appengine"
"code.google.com/p/google-api-go-client/bigquery/v2"
"code.google.com/p/mlab-ns2/gae/ns/rtt"
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/", root)
}
func root(w http.ResponseWriter, r *http.Request) {
// Getting authenticated transport with Eric's log2bq
c := appengine.NewContext(r)
service, err := rtt.BQInit(r)
q := &bigquery.QueryRequest{
Query: `SELECT
log_time,
connection_spec.server_ip,
connection_spec.client_ip,
paris_traceroute_hop.src_ip,
paris_traceroute_hop.dest_ip,
paris_traceroute_hop.rtt
FROM [measurement-lab:m_lab.2013_07]
WHERE
paris_traceroute_hop.rtt IS NOT NULL
LIMIT 30;`,
TimeoutMs: 5000,
UseQueryCache: true,
}
queryCall := bigquery.NewJobsService(service).Query("mlabns-test", q)
response, err := queryCall.Do()
if err != nil {
c.Errorf("%v\n", err)
}
w.Header().Add("content-type", "text/html")
fmt.Fprintf(w, "<p>%+v</p>", response)
fmt.Fprint(w, "<table><thead>")
for _, v := range response.Schema.Fields {
fmt.Fprintf(w, "<td>%s</td>", v.Name)
}
fmt.Fprint(w, "</thead><tbody>")
for _, v := range response.Rows {
fmt.Fprint(w, "<tr>")
for _, cell := range v.F {
fmt.Fprintf(w, "<td>%+v</td>", cell.V)
}
fmt.Fprint(w, "</tr>")
}
fmt.Fprint(w, "</tbody><table>")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment