mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-24 22:32:28 +00:00
negroni boilerplate
This commit is contained in:
parent
c96b0497e4
commit
bacf2b3666
1 changed files with 36 additions and 0 deletions
36
webhook2.go
Normal file
36
webhook2.go
Normal 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)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue