I m beginner in go lang. I have created an object array of a struct in function list and pass the address of that object array to another function changelist.In my function changelist i get it as pointer.I wanted to edit some of the fields of passed array object inside this function changedlist and pass it back to the called function list.When i try to access it in my called function i cant access the updated version from the changedlist function.
Here is my code
type Mail struct {
Name string
Address string
Status bool
Error error
}
function List(){
var addressList = make([]Mail,2)
addressList[0].Name = "Name"
addressList[0].Address = "Address"
addressList[1].Name = "Name1"
addressList[1].Address = "Address"
newAddress:=changedlist(&addressList)
fmt.Println(newAddress)
}
function Changedlist(addressList *[]Mail)*[]Mail{
for _,r:=range *addressList{
if r.Name=="Name1"{
r.Status=false
r.err=errors.New("Error in the name")
continue
}
r.Status=true
r.Error=nil
}
return addressList
}
Here what i was expecting is for name, the status will become true when i get this in my list function.But it is false which is the default value of the bool.This means that the changes are not done to the actual array struct.It is modifying the copied version.Can someone please point me in the right direction how to achieve this..Thanks.