I have created an Azure Function in Go. The function is working properly in local machine with GET & POST requests. When published, request payload sent via POST is not available in the request object. Here's my code:
# Main function
mux := http.NewServeMux()
mux.HandleFunc("/hello", helloWorld)
logrus.Fatal(http.ListenAndServe(":"+httpInvokerPort, mux))
# helloWorld function
func helloWorld(w http.ResponseWriter, r *http.Request) {
logrus.Info("hello: inside helloWorld")
bodyBuffer, err := ioutil.ReadAll(r.Body)
if err != nil {
logrus.Info("error while reading:" + err.Error())
w.Write([]byte("GO: error in reading request body"))
} else {
logrus.Info("body : " + string(bodyBuffer))
w.Write([]byte("GO: return hello"))
}
}
After deployment, I invoke a POST api request with following JSON body:
{
"a": "b"
}
In the logs, i see:
time="2020-07-31T01:14:11Z" level=info msg="body : "
function.json:
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
My code is hosted here: https://github.com/mpurusottamc/azurefunc-go
Any suggestions on how to debug this?