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.

generic.go 703B

1234567891011121314151617181920212223242526272829
  1. package httplistener
  2. import (
  3. "bytes"
  4. "github.com/irccloud/irccat/dispatcher"
  5. "net/http"
  6. )
  7. // Examples of using curl to post to /send.
  8. //
  9. // echo "Hello, world" | curl -d @- http://irccat.example.com/send
  10. // echo "#test,@alice Hello, world" | curl -d @- http://irccat.example.com/send
  11. //
  12. func (hl *HTTPListener) genericHandler(w http.ResponseWriter, request *http.Request) {
  13. if request.Method != "POST" {
  14. http.NotFound(w, request)
  15. return
  16. }
  17. body := new(bytes.Buffer)
  18. body.ReadFrom(request.Body)
  19. message := body.String()
  20. if message == "" {
  21. log.Warningf("%s - No message body in POST request", request.RemoteAddr)
  22. return
  23. }
  24. dispatcher.Send(hl.irc, message, log, request.RemoteAddr)
  25. }