Skip to content

Instantly share code, notes, and snippets.

@btc
Created February 14, 2015 23:31
Show Gist options
  • Save btc/e281050a039c9557d947 to your computer and use it in GitHub Desktop.
Save btc/e281050a039c9557d947 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"log"
"net/http"
"github.com/briantigerchow/gamecenter"
)
var mem = flag.Bool("mem", false, "run with an in-memory backed")
var db = flag.String("db", ":5432", "set the db host addr:port")
var host = flag.String("host", ":8080", "set the http host addr:port")
func main() {
flag.Parse()
log.Printf("listening at %s", *host)
var b gamecenter.GamesBackend
if *mem {
log.Println("running with an in-memory backend...")
b = gamecenter.NewMemBackend()
} else {
b = &gamecenter.PostgresBackend{*db}
}
log.Fatal(http.ListenAndServe(*host, gamecenter.Router(b)))
}
func Router(b GamesBackend) *mux.Router {
r := mux.NewRouter()
games := apiV0.Path("/games").Subrouter()
games.Methods("GET").HandlerFunc(ListGamesHandler(b))
return r
}
func ListGamesHandler(b GamesBackend) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment