github.com/go-playground/webhooks/v6@v6.3.0/_examples/single-handler/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"net/http"
     7  
     8  	"github.com/go-playground/webhooks/v6/github"
     9  )
    10  
    11  const (
    12  	path = "/webhooks"
    13  )
    14  
    15  func main() {
    16  	hook, _ := github.New(github.Options.Secret("MyGitHubSuperSecretSecrect...?"))
    17  
    18  	http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
    19  		payload, err := hook.Parse(r, github.ReleaseEvent, github.PullRequestEvent)
    20  		if err != nil {
    21  			if err == github.ErrEventNotFound {
    22  				// ok event wasn;t one of the ones asked to be parsed
    23  			}
    24  		}
    25  		switch payload.(type) {
    26  
    27  		case github.ReleasePayload:
    28  			release := payload.(github.ReleasePayload)
    29  			// Do whatever you want from here...
    30  			fmt.Printf("%+v", release)
    31  
    32  		case github.PullRequestPayload:
    33  			pullRequest := payload.(github.PullRequestPayload)
    34  			// Do whatever you want from here...
    35  			fmt.Printf("%+v", pullRequest)
    36  		}
    37  	})
    38  	http.ListenAndServe(":3000", nil)
    39  }