Skip to content

Instantly share code, notes, and snippets.

@cbrgm
Created Apr 29, 2022
Embed
What would you like to do?
Github Webhook Events in Go
package main
import (
"fmt"
"github.com/cbrgm/githubevents/githubevents"
"github.com/google/go-github/v43/github"
"net/http"
)
func main() {
// create a new event handler
handle := githubevents.New("secretkey")
// add callbacks
handle.OnIssueCommentCreated(
func(deliveryID string, eventName string, event *github.IssueCommentEvent) error {
fmt.Printf("%s made a comment!", event.Sender.Login)
return nil
},
)
// add a http handleFunc
http.HandleFunc("/hook", func(w http.ResponseWriter, r *http.Request) {
err := handle.HandleEventRequest(r)
if err != nil {
fmt.Println("error")
}
})
// start the server listening on port 8080
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment