server.go 523 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "bytes"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. )
  8. func alert(w http.ResponseWriter, req *http.Request) {
  9. buf, bodyErr := ioutil.ReadAll(req.Body)
  10. if bodyErr != nil {
  11. log.Print("bodyErr ", bodyErr.Error())
  12. http.Error(w, bodyErr.Error(), http.StatusInternalServerError)
  13. return
  14. }
  15. rdr1 := ioutil.NopCloser(bytes.NewBuffer(buf))
  16. log.Printf("BODY: %q", rdr1)
  17. }
  18. func main() {
  19. http.Handle("/", http.FileServer(http.Dir("web")))
  20. http.HandleFunc("/alert", alert)
  21. http.ListenAndServe(":9090", nil)
  22. }