Created
April 29, 2022 09:31
-
-
Save cbrgm/db3652fb21bc4db905335fcee848f085 to your computer and use it in GitHub Desktop.
Github Webhook Events in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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