Hi i am process of learning the Go language, and i want to ask how to create empty Object/Struct as domain model data type? i am using Fiber as my framework and here is the example of what i want to get from golang response api is something like this :
{
"success": true,
"message": "Success registered",
"data": {
"first_name": "asdfa",
"last_name": "asdfa",
"email": "fadsfa",
"password": "asdfasfas"
}
}
and here is how i try, here is my responseDto.go :
type ResponseDto struct {
Success bool `json:"success"`
Message string `json:"message"`
Data fiber.Map `json:"data"`
}
then here is how my controller looked like :
func Register(c *fiber.Ctx) error {
user := request.UserRequest{}
//do something then return
return c.JSON(models.ResponseDto{
Success: false,
Message: "Success registered",
Data: fiber.Map{
"data": user,
},
})
}
then here is the response :
{
"success": false,
"message": "Success registered",
"data": {
"data": {
"first_name": "asdfa",
"last_name": "asdfa",
"email": "fadsfa",
"password": "asdfasfas"
}
}
}
as you can see, i will have nested data, but i don't want it to be nested, i want it just one level nested, like my example . How can i achieve it? what data type should i use and how to use it to assign the value?
You have to "convert" user to fiber.Map
Or you can change ResponseDto