webhook.go 797 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // webhook.go is a simple example program that will listen upon
  2. // localhost:8080 and dump the contents of any HTTP POST received
  3. // to the console.
  4. //
  5. package main
  6. import (
  7. "fmt"
  8. "io"
  9. "io/ioutil"
  10. "log"
  11. "net/http"
  12. )
  13. // HandleHook is called on any access to the server-root.
  14. //
  15. // If a POST request is received dump it to the console. Regardless
  16. // of the requested method we then send an "OK" response to the caller.
  17. func HandleHook(w http.ResponseWriter, r *http.Request) {
  18. if r.Method == "POST" {
  19. content, _ := ioutil.ReadAll(r.Body)
  20. fmt.Printf("%s\n", content)
  21. }
  22. // Always return a response to the caller.
  23. io.WriteString(w, "OK\n")
  24. }
  25. func main() {
  26. // Bind our handler
  27. http.HandleFunc("/", HandleHook)
  28. // Launch the server
  29. log.Fatal(http.ListenAndServe(":8080", nil))
  30. }