blob: 27fb2e0434b26c01a24c9a8d71de7b62322d065e [file] [log] [blame]
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)
}
}