package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/google/go-github/github"
	"github.com/rjz/githubhook"
)

func hello(rw http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(rw, "This is stalemate.")
}

func processPayload(rw http.ResponseWriter, req *http.Request) {
	hook, err := githubhook.Parse([]byte(os.Getenv("STALEMATE_SECRET_TOKEN")), req)
	if err != nil {
		log.Println(err)
		return
	}

	switch hook.Event {
	case "integration_installation":
		event := github.IntegrationInstallationEvent{}
		if err := json.Unmarshal(hook.Payload, &event); err != nil {
			log.Println(err)
			return
		}
		// Echo back the installation part of the payload.
		fmt.Fprintf(rw, event.Installation.String())

	default:
		log.Printf("not handling %s events yet", hook.Event)
	}

}

func main() {
	http.HandleFunc("/", hello)
	http.HandleFunc("/events", processPayload)
	if err := http.ListenAndServe(":9090", nil); err != nil {
		log.Fatal(err)
	}
}

package main

import (
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
)

func hello(rw http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(rw, "This is stalemate.")
}

func processPayload(rw http.ResponseWriter, req *http.Request) {
	dump, err := httputil.DumpRequest(req, true)
	if err != nil {
		log.Println(err)
	}
	log.Println(string(dump))
	fmt.Fprintf(rw, "{\"status\": \"ok\"}\n")
}

func main() {
	http.HandleFunc("/", hello)
	http.HandleFunc("/events", processPayload)
	if err := http.ListenAndServe(":9090", nil); err != nil {
		log.Fatal(err)
	}
}

--- 
+++ 
@@ -1,10 +1,14 @@
 package main
 
 import (
+	"encoding/json"
 	"fmt"
 	"log"
 	"net/http"
-	"net/http/httputil"
+	"os"
+
+	"github.com/google/go-github/github"
+	"github.com/rjz/githubhook"
 )
 
 func hello(rw http.ResponseWriter, req *http.Request) {
@@ -12,12 +16,26 @@
 }
 
 func processPayload(rw http.ResponseWriter, req *http.Request) {
-	dump, err := httputil.DumpRequest(req, true)
+	hook, err := githubhook.Parse([]byte(os.Getenv("STALEMATE_SECRET_TOKEN")), req)
 	if err != nil {
 		log.Println(err)
+		return
 	}
-	log.Println(string(dump))
-	fmt.Fprintf(rw, "{\"status\": \"ok\"}\n")
+
+	switch hook.Event {
+	case "integration_installation":
+		event := github.IntegrationInstallationEvent{}
+		if err := json.Unmarshal(hook.Payload, &event); err != nil {
+			log.Println(err)
+			return
+		}
+		// Echo back the installation part of the payload.
+		fmt.Fprintf(rw, event.Installation.String())
+
+	default:
+		log.Printf("not handling %s events yet", hook.Event)
+	}
+
 }
 
 func main() {
Use client libraries to parse installation event
