I have a specific problem where I need a variable that can take the value of one or another structure. I create a userResp structure with a user field which has the value of an interface, but if I add a function that returns a sub property of user called Password, returns error. The value of user will be a struct that have the Password property.
The struct:
type userResp struct {
user interface{}
}
the function
func (ur *userResp) password() string {
return ur.user.Password
}
I get ur.user.Password undefined (type interface {} is interface with no methods)
but the interface user
can be a Admin or User struct with a Password
field.
Any idea how do this, I need to work with an struct of either the user or admin and return it.
I can't use 2 functions because the logic is the same in both cases. I need the entire struct of User or Admin