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.

46 lines
662 B

  1. package main
  2. import (
  3. "io"
  4. "log"
  5. "net/http"
  6. )
  7. type HookHandler interface {
  8. ServeHTTP(http.ResponseWriter, *http.Request)
  9. }
  10. type Condition struct {
  11. selector string
  12. tester string
  13. value string
  14. }
  15. type Hook struct {
  16. Name string
  17. params []Condition
  18. actions []string
  19. }
  20. type ByName []Hook
  21. func (h ByName) Len() int {
  22. return len(h)
  23. }
  24. func (h ByName) Less(i, j int) bool {
  25. return h[i].Name < h[j].Name
  26. }
  27. func (h ByName) Swap(i, j int) {
  28. h[i], h[j] = h[j], h[i]
  29. }
  30. func (h Hook) String() string {
  31. return h.Name
  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. }