Answer the question
In order to leave comments, you need to log in
Go how to add a field to a structure that I embed?
Hey guys. Happy coming everyone!
Who fumbles for go, please tell me
Is there a basic structure of the answer
Is it possible to somehow add one more field to the body in the login structure .. Like this
Or how to do it beautifully? Obviously, you need to add Code, Message to all structures, because suddenly, instead of the expected response, an error will come
. How to make this hierarchy of structures beautiful so that you can decode normally?
Answer the question
In order to leave comments, you need to log in
If I understand correctly how to do it, then this is how you can do it:
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
type LoginResponse struct {
Response
Token string
}
response := LoginResponse{
Response : Response {
Code: 10,
Message: `error / success message`,
},
Token: `token`,
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question