github.com/go-playground/webhooks/v6@v6.3.0/README.md (about)

     1  Library webhooks
     2  ================
     3  <img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v6/logo.png">![Project status](https://img.shields.io/badge/version-6.3.0-green.svg)
     4  [![Test](https://github.com/go-playground/webhooks/workflows/Test/badge.svg?branch=master)](https://github.com/go-playground/webhooks/actions)
     5  [![Coverage Status](https://coveralls.io/repos/go-playground/webhooks/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/webhooks?branch=master)
     6  [![Go Report Card](https://goreportcard.com/badge/go-playground/webhooks)](https://goreportcard.com/report/go-playground/webhooks)
     7  [![GoDoc](https://godoc.org/github.com/go-playground/webhooks/v6?status.svg)](https://godoc.org/github.com/go-playground/webhooks/v6)
     8  ![License](https://img.shields.io/dub/l/vibe-d.svg)
     9  
    10  Library webhooks allows for easy receiving and parsing of GitHub, Bitbucket, GitLab, Docker Hub, Gogs and Azure DevOps Webhook Events
    11  
    12  Features:
    13  
    14  * Parses the entire payload, not just a few fields.
    15  * Fields + Schema directly lines up with webhook posted json
    16  
    17  Notes:
    18  
    19  * Currently only accepting json payloads.
    20  
    21  Installation
    22  ------------
    23  
    24  Use go get.
    25  
    26  ```shell
    27  go get -u github.com/go-playground/webhooks/v6
    28  ```
    29  
    30  Then import the package into your own code.
    31  
    32  	import "github.com/go-playground/webhooks/v6"
    33  
    34  Usage and Documentation
    35  ------
    36  
    37  Please see http://godoc.org/github.com/go-playground/webhooks/v6 for detailed usage docs.
    38  
    39  ##### Examples:
    40  ```go
    41  package main
    42  
    43  import (
    44  	"fmt"
    45  
    46  	"net/http"
    47  
    48  	"github.com/go-playground/webhooks/v6/github"
    49  )
    50  
    51  const (
    52  	path = "/webhooks"
    53  )
    54  
    55  func main() {
    56  	hook, _ := github.New(github.Options.Secret("MyGitHubSuperSecretSecret...?"))
    57  
    58  	http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
    59  		payload, err := hook.Parse(r, github.ReleaseEvent, github.PullRequestEvent)
    60  		if err != nil {
    61  			if err == github.ErrEventNotFound {
    62  				// ok event wasn't one of the ones asked to be parsed
    63  			}
    64  		}
    65  		switch payload.(type) {
    66  
    67  		case github.ReleasePayload:
    68  			release := payload.(github.ReleasePayload)
    69  			// Do whatever you want from here...
    70  			fmt.Printf("%+v", release)
    71  
    72  		case github.PullRequestPayload:
    73  			pullRequest := payload.(github.PullRequestPayload)
    74  			// Do whatever you want from here...
    75  			fmt.Printf("%+v", pullRequest)
    76  		}
    77  	})
    78  	http.ListenAndServe(":3000", nil)
    79  }
    80  
    81  ```
    82  
    83  Contributing
    84  ------
    85  
    86  Pull requests for other services are welcome!
    87  
    88  If the changes being proposed or requested are breaking changes, please create an issue for discussion.
    89  
    90  License
    91  ------
    92  
    93  Distributed under MIT License, please see license file in code for more details.