ghook

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

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 9 Imported by: 0

README

ghook godoc

ghook is a small Go package for receiving GitHub web hooks.

Example usage:

package main

import (
    "fmt"
    "net/http"

    "github.com/alexbakker/ghook"
)

var (
    secret = []byte("d696f82431664d9ea93483789db0116c")
)

func main() {
    hook := ghook.New(secret, func(event *ghook.Event) error {
        fmt.Printf("received %s event!\n", event.Name)
        return nil
    })

    panic(http.ListenAndServe("127.0.0.1:8080", hook))
}

You can then use the go-github package to parse the payload.

github-hook-receiver

An example usecase for ghook is cmd/github-hook-receiver. It's a simple HTTP service that receives hooks and handles them according to a list of handlers defined in a config file.

Usage of github-hook-receiver:
  -addr string
    	address to listen on (default "127.0.0.1:8080")
  -config string
    	the filename of the configuration file (default "config.json")

The configuration file should have the following format:

{
    "secret": "d696f82431664d9ea93483789db0116c",
    "handlers": [
        {
            "repo": "alexbakker/site",
            "ref": "refs/heads/master",
            "command": "/usr/local/bin/update-blog"
        }
    ]
}

Documentation

Overview

Package ghook provides a minimal toolset for receiving with GitHub web hooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(event *Event) error

Callback is the type of function that is called when a GitHub web hook request is received and verified.

type Event

type Event struct {
	Name    string
	GUID    string
	Payload []byte
}

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

func New

func New(secret []byte, cb Callback) *Hook

func (*Hook) ServeHTTP

func (h *Hook) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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