Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Commit

Permalink
use deferpanic
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Apr 13, 2015
1 parent f78a94b commit 1fc96f3
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package main
import (
"fmt"
"github.com/codegangsta/negroni"
"github.com/deferpanic/deferclient/deferstats"
"github.com/fzzy/radix/extra/pool"
"github.com/fzzy/radix/redis"
"github.com/google/go-github/github"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"github.com/namsral/flag"
"github.com/unrolled/render"
// "github.com/deferpanic/deferclient/errors"
"golang.org/x/oauth2"
githuboauth "golang.org/x/oauth2/github"
"math/rand"
Expand Down Expand Up @@ -218,6 +220,12 @@ func domainkeyDeleteHandler(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req, "/#auth", http.StatusFound)
}

// This is just a temporary thing to try out deferpanic.com
// and this can be removed once I know it works.
func errorTestHandler(w http.ResponseWriter, req *http.Request) {
panic("Something terrible happened")
}

var (
redisPool *pool.Pool
procs int
Expand Down Expand Up @@ -252,6 +260,7 @@ func main() {
clientSecret = ""
hashKey = "randomishstringthatsi32charslong"
blockKey = "randomishstringthatsi32charslong"
deferPanicKey = ""
)
flag.IntVar(&port, "port", port, "Port to start the server on")
flag.IntVar(&procs, "procs", 1, "Number of CPU processors (0 to use max)")
Expand All @@ -278,8 +287,16 @@ func main() {
flag.StringVar(
&blockKey, "blockKey", blockKey,
"Block key to encrypt cookie values")
flag.StringVar(
&deferPanicKey, "deferPanicKey", deferPanicKey,
"Auth key for deferpanic.com")
flag.Parse()

if deferPanicKey != "" {
deferstats.Token = deferPanicKey
go deferstats.CaptureStats()
}

oauthConf.ClientID = clientID
oauthConf.ClientSecret = clientSecret

Expand Down Expand Up @@ -331,19 +348,20 @@ func main() {
errHndlr(err)

mux := mux.NewRouter()
mux.HandleFunc("/", indexHandler).Methods("GET", "HEAD")
mux.HandleFunc("/v1/ping", pingHandler).Methods("GET", "HEAD")
mux.HandleFunc("/v1", fetchHandler).Methods("GET", "HEAD")
mux.HandleFunc("/v1", updateHandler).Methods("POST", "PUT")
mux.HandleFunc("/v1", deleteHandler).Methods("DELETE")
mux.HandleFunc("/v1/stats", privateStatsHandler).Methods("GET")
mux.HandleFunc("/v1/flush", flushHandler).Methods("DELETE")
mux.HandleFunc("/v1/bulk", bulkHandler).Methods("POST", "PUT")
mux.HandleFunc("/login", handleGitHubLogin).Methods("GET")
mux.HandleFunc("/logout", logoutHandler).Methods("GET", "POST")
mux.HandleFunc("/github_oauth_cb", handleGitHubCallback).Methods("GET")
mux.HandleFunc("/domainkeys/new", domainkeyNewHandler).Methods("POST")
mux.HandleFunc("/domainkeys/delete", domainkeyDeleteHandler).Methods("POST")
mux.HandleFunc("/", deferstats.HTTPHandler(indexHandler)).Methods("GET", "HEAD")
mux.HandleFunc("/v1/ping", deferstats.HTTPHandler(pingHandler)).Methods("GET", "HEAD")
mux.HandleFunc("/v1", deferstats.HTTPHandler(fetchHandler)).Methods("GET", "HEAD")
mux.HandleFunc("/v1", deferstats.HTTPHandler(updateHandler)).Methods("POST", "PUT")
mux.HandleFunc("/v1", deferstats.HTTPHandler(deleteHandler)).Methods("DELETE")
mux.HandleFunc("/v1/stats", deferstats.HTTPHandler(privateStatsHandler)).Methods("GET")
mux.HandleFunc("/v1/flush", deferstats.HTTPHandler(flushHandler)).Methods("DELETE")
mux.HandleFunc("/v1/bulk", deferstats.HTTPHandler(bulkHandler)).Methods("POST", "PUT")
mux.HandleFunc("/login", deferstats.HTTPHandler(handleGitHubLogin)).Methods("GET")
mux.HandleFunc("/logout", deferstats.HTTPHandler(logoutHandler)).Methods("GET", "POST")
mux.HandleFunc("/github_oauth_cb", deferstats.HTTPHandler(handleGitHubCallback)).Methods("GET")
mux.HandleFunc("/domainkeys/new", deferstats.HTTPHandler(domainkeyNewHandler)).Methods("POST")
mux.HandleFunc("/domainkeys/delete", deferstats.HTTPHandler(domainkeyDeleteHandler)).Methods("POST")
mux.HandleFunc("/errortest", deferstats.HTTPHandler(errorTestHandler)).Methods("GET")

n := negroni.Classic()

Expand Down

0 comments on commit 1fc96f3

Please sign in to comment.