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

  1. package main
  2. import (
  3. "io"
  4. "log"
  5. "net/http"
  6. )
  7. // HookHandler is an interface that satisfies an http handler.
  8. // Something else here
  9. type HookHandler interface {
  10. ServeHTTP(http.ResponseWriter, *http.Request)
  11. }
  12. // Condition for a hook. It contains something to select.
  13. // This could be a piece of json post data, a method, or http header
  14. // The tester is the operation to do on the selector.
  15. // For example: AND, OR, NOT, LESS THAN, GREATER THAN, EQUALS, CONTAINS
  16. type Condition struct {
  17. selector string
  18. tester string
  19. actions []Action
  20. }
  21. // Action results from when a condition is expressed
  22. // For example, an action could run if a selector returns TRUE when tested
  23. // while another action could be run when FALSE is returned
  24. type Action interface {
  25. Run() error
  26. }
  27. // Hook that will be run when a user hits the appropriate URL
  28. // with the right methods and parameters.
  29. type Hook struct {
  30. Name string
  31. conditions []Condition
  32. }
  33. func (h Hook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  34. log.Println(r.URL.String())
  35. io.WriteString(w, h.Name+"\n")
  36. }