webhook

package module
v0.0.0-...-fd8c61b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2015 License: MIT Imports: 12 Imported by: 1

README

# webhook

webhook (go-github-webhook) provides Github webhook adapter for golang.

**Example to hook push event**

```go
package main

import (
    "log"
    "net/http"

    "github.com/koron/go-github-webhook"
)

func main() {
    // To verify webhook's payload, set secret by SetSecret().
    webhook.SetSecret([]byte("abcdefgh"))

    // Add a HandlerFunc to process webhook.
    http.HandleFunc("/", webhook.HandlePush(func(ev *webhook.Event) {
        push := ev.PushEvent()
        if push == nil {
            return
        }
        log.Printf("push: verified=%v %#v", ev.Verified, push)
    }))

    // Start web server.
    log.Fatal(http.ListenAndServe(":8080", nil))
}
```

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BodyMaxLen int64 = 1024 * 1024

BodyMaxLen limits max size of payload.

Functions

func Handle

func Handle(f HandlerFunc) http.HandlerFunc

Handle generates http.HandlerFunc to handle webhook events.

func HandlePush

func HandlePush(f HandlerFunc) http.HandlerFunc

HandlePush generates http.HandlerFunc to handle webhook push events.

func SetLogger

func SetLogger(l *log.Logger)

SetLogger set logger object for webhook

func SetSecret

func SetSecret(v []byte)

SetSecret set secret to verify webhook payload.

Types

type Commit

type Commit struct {
	ID        string
	Distinct  bool
	Message   string
	Timestamp string
	URL       string
	Added     []string
	Removed   []string
	Modified  []string
}

Commit represents a Github's commit.

type Event

type Event struct {
	Header   Header
	Body     []byte
	Verified bool
}

Event represents raw event of Github's webhook.

func Parse

func Parse(r *http.Request, secret []byte) (*Event, error)

Parse parses a HTTP request as Github's webhook.

func (*Event) PushEvent

func (r *Event) PushEvent() *PushEvent

PushEvent returns a PushEvent struct.

type HandlerFunc

type HandlerFunc func(ev *Event)

HandlerFunc handles webhook events.

type Header struct {
	EventType string
	Signature string
	Deliverty string
}

Header represents webhook's delivery headers.

type PushEvent

type PushEvent struct {
	Ref        string
	Before     string
	After      string
	Created    bool
	Deleted    bool
	Forced     bool
	Compare    string
	Commits    []Commit
	Repository Repository
}

PushEvent represents a Github's webhook push event.

type Repository

type Repository struct {
	Name        string
	FullName    string
	Private     bool
	HTMLURL     string `json:"html_url"`
	Description string
	Fork        bool
	URL         string
	CreatedAt   int64  `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
	PushedAt    int64  `json:"pushed_at"`
}

Repository represents a Github's repository.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL