ghooks

package module
v0.0.0-...-92ac1e3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: MIT Imports: 10 Imported by: 2

README

ghooks

ghooks is github hooks receiver. inspired by GitHub::Hooks::Receiver, octoks

Install

go get github.com/Konboi/ghooks

Usage

// sample.go
package main

import (
    "fmt"
    "log"

    "github.com/Konboi/ghooks"
)


func main() {
    port := 8080
    hooks := ghooks.NewServer(port)

    hooks.On("push", pushHandler)
    hooks.On("pull_request", pullRequestHandler)
    hooks.Run()
}

func pushHandler(payload interface{}) {
    fmt.Println("puuuuush")
}

func pullRequestHandler(payload interface{}) {
    fmt.Println("pull_request")
}
go run sample.go
curl -H "X-GitHub-Event: push" -d '{"hoge":"fuga"}' http://localhost:8080
> puuuuush

Documentation

Index

Constants

View Source
const (
	VERSION = 0.2
)

Variables

This section is empty.

Functions

func Emit

func Emit(name string, payload interface{})

Types

type Hook

type Hook struct {
	Event string
	Func  func(payload interface{})
}

type Hooks

type Hooks struct {
	Hooks []Hook
}

type Server

type Server struct {
	Port   int
	Secret string
	Host   string
}

func NewServer

func NewServer(port int, hosts ...string) *Server

func (*Server) On

func (s *Server) On(name string, handler func(payload interface{}))

func (*Server) Receiver

func (s *Server) Receiver(w http.ResponseWriter, req *http.Request)

func (*Server) Run

func (s *Server) Run() error

Jump to

Keyboard shortcuts

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