I am trying to set the value of a property in a concrete struct, with a method that uses and interface implemented by that struct. The struct is also composed by another struct.
With the sample below userId value remains "aaaa" and is not updated to "userid1".
How can I update values of struct through a method interface as parameter and the struct as argument?
func main() {
user:=User{}
mw:=SomeMiddleware{}
user.UserId="aaaa"
mw.Process(user)
fmt.Println("UserId: " + user.UserId)
}
type IUser interface {
SetUserId(string)
}
type SomeMiddleware struct {
}
func(m SomeMiddleware) Process(user IUser){
user.SetUserId("userid1")
}
type User struct {
UserInfo
}
type UserInfo struct {
UserId string
}
func(ui UserInfo) SetUserId(userId string) {
ui.UserId=userId
}