MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/golang-samples / handler

Function handler

docs/appengine/cloudsql/cloudsql.go:50–75  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

48}
49
50func handler(w http.ResponseWriter, r *http.Request) {
51 if r.URL.Path != "/" {
52 http.NotFound(w, r)
53 return
54 }
55
56 w.Header().Set("Content-Type", "text/plain")
57
58 rows, err := db.Query("SHOW DATABASES")
59 if err != nil {
60 http.Error(w, fmt.Sprintf("Could not query db: %v", err), 500)
61 return
62 }
63 defer rows.Close()
64
65 buf := bytes.NewBufferString("Databases:\n")
66 for rows.Next() {
67 var dbName string
68 if err := rows.Scan(&dbName); err != nil {
69 http.Error(w, fmt.Sprintf("Could not scan result: %v", err), 500)
70 return
71 }
72 fmt.Fprintf(buf, "- %s\n", dbName)
73 }
74 w.Write(buf.Bytes())
75}
76
77func mustGetenv(k string) string {
78 v := os.Getenv(k)

Callers

nothing calls this directly

Calls 2

ErrorMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected