-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
I have two goals:
- Remove the amount of boilerplate you have to write if you want to create a small app listening to webhooks,
- Hide the
event interface{}cast to actual type from the user.
I'm proposing something like this:
whl := NewWebHookListener("my-github-secret")
// Mimic http.Handler
type MyCommitCommentEventHandler struct{}
func (MyCommitCommentEventHandler) ProcessHook(w http.ResponseWriter, event CommitCommentEvent) {
fmt.Println("Received CommitCommentEvent:", event)
w.Write([]byte("OK"))
}
// The following two functions mimic net/http Handle() and HandleFunc()
whl.CommitCommentEventHandle(MyCommitCommentEventHandler{})
whl.CommitCommentEventHandleFunc(func(w http.ResponseWriter, event CommitCommentEvent) {
fmt.Println("Received CommitCommentEvent:", event)
w.Write([]byte("OK"))
})
// Add *Handle and *HandleFunc for each type of events.
log.Fatal(whl.ListenAndProcess(":8080"))Is that something you would be interested in merging in your tree?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels