I'm new in Golang, I've been doing some code tests to build an REST API using Iris framework, I'm trying to get the body data from a Post to my API but I cannot make it works, I did read the Body binder http://iris-go.com/body_binder/ and followed the examples. The result I get is an empty structure:
My code:
package main
import (
"github.com/kataras/iris"
"fmt"
)
type PostAPI struct {
*iris.Context
}
type Lead struct {
fbId string
email string
telefono string
version string
mac string
os string
}
func (p PostAPI) Post(){
lead := Lead{}
err := p.ReadJSON(&lead)
if (err != nil) {
fmt.Println("Error on reading form: " + err.Error())
return
}
fmt.Printf("Post! %v", lead)
}
func main() {
iris.API("/", PostAPI{})
iris.Listen(":8080")
}
The post:
curl -H "Content-Type: application/json" -X POST -d '{"fbId": "werwer","email": "werwer@gmail.com","telefono": "5555555555","version": "123","mac": "3j:3j:3j:3j","os": "uno bien chido"}' http://0.0.0.0:8080/
The result:
Post! { }
What am I doing wrong?