Skip to content

Instantly share code, notes, and snippets.

@cbrgm
Created April 29, 2022 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbrgm/db3652fb21bc4db905335fcee848f085 to your computer and use it in GitHub Desktop.
Save cbrgm/db3652fb21bc4db905335fcee848f085 to your computer and use it in GitHub Desktop.
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