From e55184e1e92c153d901116aa076d505ef4446d50 Mon Sep 17 00:00:00 2001 From: rjz Date: Fri, 5 Aug 2016 10:06:51 -0700 Subject: [PATCH] Adds `Extract` method to `Hook` Github webhooks are always JSON: consumers of this library shouldn't need to negotiate payload format. --- githubhook.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/githubhook.go b/githubhook.go index e783a68..1b888c3 100644 --- a/githubhook.go +++ b/githubhook.go @@ -5,6 +5,7 @@ import ( "crypto/hmac" "crypto/sha1" "encoding/hex" + "encoding/json" "errors" "io/ioutil" "net/http" @@ -60,6 +61,11 @@ func (h *Hook) SignedBy(secret []byte) bool { return hmac.Equal(signBody(secret, h.Payload), actual) } +// Extract unmarshals Payload into a destination interface. +func (h *Hook) Extract(dst interface{}) error { + return json.Unmarshal(h.Payload, dst) +} + // New reads a Hook from an incoming HTTP Request. func New(req *http.Request) (hook *Hook, err error) { hook = new(Hook)