Add Examples + Complete README

This commit is contained in:
joeybloggs
2015-10-30 13:54:32 -04:00
parent 9af9035c2b
commit 24cb1f6a1d
3 changed files with 245 additions and 2 deletions
+43
View File
@@ -0,0 +1,43 @@
package main
import (
"fmt"
"strconv"
"github.com/joeybloggs/webhooks"
"github.com/joeybloggs/webhooks/github"
)
const (
path = "/webhooks"
port = 80
)
func main() {
hook := github.New(&github.Config{Secret: "MyGitHubSuperSecretSecrect...?"})
hook.RegisterEvents(HandleMultiple, github.ReleaseEvent, github.PullRequestEvent) // Add as many as you want
err := webhooks.Run(hook, ":"+strconv.Itoa(port), path)
if err != nil {
fmt.Println(err)
}
}
// HandleMultiple handles multiple GitHub events
func HandleMultiple(payload interface{}) {
fmt.Println("Handling Payload..")
switch payload.(type) {
case github.ReleasePayload:
release := payload.(github.ReleasePayload)
// Do whatever you want from here...
fmt.Printf("%+v", release)
case github.PullRequestPayload:
pullRequest := payload.(github.PullRequestPayload)
// Do whatever you want from here...
fmt.Printf("%+v", pullRequest)
}
}