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