```
type student struct {
id int
name string
age string
}
func Inform(){
var ss student
ss.id = 1
ss.name = "小小"
ss.age = 18
StudentData(&ss) // 这里面传的是地址
fmt.Println("ss:",ss)
}
func StudentData(params interface{}){
// 1:怎么通过反射获取外部传进来的结构体中的成员地址
// 2:通过反射修改的结构体中成员的值
}
```
查了一晚上,如果不是结构体只是普通的变量如int之类的,那传入地址给interface后,通过反射修改值可以实现了,但是换成结构体传入地址后怎么试都不行,蒙了……
```go
func StudentData(params interface{}) {
if *(*uint8)(unsafe.Add(*(*unsafe.Pointer)(unsafe.Pointer(&params)), 8<<(^uint(0)>>63)+4+3))&32 == 0 {
panic("readonly!")
}
base := *(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&params), 4<<(^uint(0)>>63)))
newid, newname, newage := 1, "小小", 18
*(*int)(unsafe.Add(base, 0)) = newid
*(*unsafe.Pointer)(unsafe.Add(base, 4<<(^uint(0)>>63))) = *(*unsafe.Pointer)(unsafe.Pointer(&newname))
*(*int)(unsafe.Add(base, 4<<(^uint(0)>>63)*2)) = len(newname)
*(*int)(unsafe.Add(base, 4<<(^uint(0)>>63)*3)) = newage
}
```
#5