hswaw/oodviewer: init

This brings oodviewer into k0.

oodviewer started as a py2/flask script running on q3k's personal infra,
which is now being turned down.

This is a rewrite of that script into similarly mediocre Go, conforming
to the exact same mediocre JSON API and spartan HTML interface.

This also deploys it into k0 in the oodviewer-prod namespace. It's
already running, but the 'oodviewer.q3k.me' TTL has to expire before it
begins handling traffic.

Change-Id: Ieef1b0f8f0c60e6fa5dbe7701e0a07a4257f99ce
diff --git a/hswaw/oodviewer/main.go b/hswaw/oodviewer/main.go
new file mode 100644
index 0000000..27fb2e0
--- /dev/null
+++ b/hswaw/oodviewer/main.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+	"math/rand"
+	"net/http"
+	"time"
+
+	"github.com/golang/glog"
+)
+
+var (
+	flagPostgres string
+	flagListen   string
+)
+
+func init() {
+	flag.Set("logtostderr", "true")
+}
+
+func handleRobots(w http.ResponseWriter, r *http.Request) {
+	// Prevent indexing by any (honest) search engine.
+	fmt.Fprintf(w, "User-agent: *\nDisallow: /\n")
+}
+
+func main() {
+	flag.StringVar(&flagPostgres, "postgres", "", "Postgres connection string (see lib/pq docs)")
+	flag.StringVar(&flagListen, "listen", "127.0.0.1:8080", "Address to listen at for public HTTP traffic")
+	flag.Parse()
+
+	rand.Seed(time.Now().Unix())
+
+	a, err := newApp(flagPostgres)
+	if err != nil {
+		glog.Exitf("newApp: %v", err)
+	}
+
+	http.HandleFunc("/robots.txt", handleRobots)
+
+	http.HandleFunc("/terms.json", a.handleTermsJson)
+	http.HandleFunc("/term.json/", a.handleTermJson)
+	http.HandleFunc("/randomterm.json/", a.handleRandomTermJson)
+
+	http.HandleFunc("/terms", a.handleTerms)
+	http.HandleFunc("/", a.handleTerms)
+
+	http.HandleFunc("/term/", a.handleTerm)
+
+	glog.Infof("Listening at %q", flagListen)
+	if err := http.ListenAndServe(flagListen, nil); err != nil {
+		glog.Exit(err)
+	}
+}