Skip to content

Instantly share code, notes, and snippets.

@xiaoping378
Created December 27, 2016 02:07
Show Gist options
  • Save xiaoping378/9c449f29166e37fa316571d6c6107055 to your computer and use it in GitHub Desktop.
Save xiaoping378/9c449f29166e37fa316571d6c6107055 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func printPost(rw http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
req.Body.Close()
if err != nil {
log.Fatal("ReadAll: ", err)
}
fmt.Println(string(body))
}
func main() {
http.HandleFunc("/alerts", printPost)
if err := http.ListenAndServe(":4000", nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment