Skip to content

Instantly share code, notes, and snippets.

@cbrgm
Created April 29, 2022 09:32
Show Gist options
  • Save cbrgm/52bdc3a6418b1b948ac59c6fbdc8759e to your computer and use it in GitHub Desktop.
Save cbrgm/52bdc3a6418b1b948ac59c6fbdc8759e to your computer and use it in GitHub Desktop.
Github Webhooks Golang
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