Captain Hook - Web hook server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1.0 KiB

package main
import (
"io"
"log"
"net/http"
)
// HookHandler is an interface that satisfies an http handler.
// Something else here
type HookHandler interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
// Condition for a hook. It contains something to select.
// This could be a piece of json post data, a method, or http header
// The tester is the operation to do on the selector.
// For example: AND, OR, NOT, LESS THAN, GREATER THAN, EQUALS, CONTAINS
type Condition struct {
selector string
tester string
actions []Action
}
// Action results from when a condition is expressed
// For example, an action could run if a selector returns TRUE when tested
// while another action could be run when FALSE is returned
type Action interface {
Run() error
}
// Hook that will be run when a user hits the appropriate URL
// with the right methods and parameters.
type Hook struct {
Name string
conditions []Condition
}
func (h Hook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(r.URL.String())
io.WriteString(w, h.Name+"\n")
}