I'm asking myself about an error that I got.. I'm making an API which send a response which seems like it:
var StatusBack struct {
Description string // to describe the error/the result
StatusId int // the status number (500 Internal error, 200 OK...)
}
// client get
{
description: "{surname: \"Xthing\", firstname: \"Mister\"}"
status_id: 200
}
So my idea was to make a json into a string with Marshal and then, Marshal a second time the StatusBack struct to send it. However, it doesn't make what I really want which is to get an object which contain another object. The client only get one object which contain a string..The thing is, I don't send only user as result, so like I show below I think I need an interface
var StatusBack struct {
Description string // to describe the error
Result <Interface or object, I don t know> // which is the result
StatusId int // the status number (500 Internal error, 200 OK...)
}
// client get
{
description: "User information",
result: {
surname: "Xthing",
firstname: "Mister"
},
status_id: 200
}
Like I said before, I not only send user, it could be lot of different object, so how can I achieves it? Does my second idea is better? If yes, how can I code it?
Thank !