First of all, I'm trying to create a logging service in Go, where it is a lightweight server accepting POST requests with log data from my service. I'm writing this service in Go because it is supposed to be fast and handle a lot of POST requests at once. Is my logic sound there?
Anyways, this is my issue. I'm sending POST requests like this to test:
curl -H "Content-Type: application/json" -X POST -d '{"hello":"world"}' http://localhost:8080/log
And here is my Go script so far:
package main
import (
"fmt"
"log"
"net/http"
)
func logger(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.Form)
fmt.Println(r.FormValue("hello"))
}
func main() {
http.HandleFunc("/log", logger)
log.Fatal(http.ListenAndServe(":8080", nil))
}
It is outputting:
map []
Why is that? How could I write the POST data to a file on the server?
Thank you very much! W