negroni boilerplate

This commit is contained in:
Adnan Hajdarevic 2015-03-11 16:48:52 +01:00
parent c96b0497e4
commit bacf2b3666

36
webhook2.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"fmt"
"net/http"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/hooks/{id}", hookHandler)
n := negroni.Classic()
n.UseHandler(router)
n.Run(":9000")
}
func hookHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
// parse headers
// parse body
// find hook
// trigger hook
// say thanks
fmt.Fprintf(w, "Thanks. %s %+v %+v %+v", id, vars, r.Header, r.Body)
}