增量删除是很重要的,比如说在update的方法里面会出现这样的情况。
type demoStruct struct {
Replaced string
Remain string
}
func main() {
oldInfo := demoStruct{Replaced: "You can see me no more", Remain: "I still here"}
fmt.Println(oldInfo.Replaced," ",oldInfo.Remain)
newInfo := demoStruct{Replaced: "I replace my ancester:)"}
incrementallyUpdate(&oldInfo,&newInfo)
fmt.Println(oldInfo.Replaced," ",oldInfo.Remain)
}
func incrementallyUpdate(update *demoStruct,info *demoStruct){
updateS:=reflect.ValueOf(update).Elem()
infoS:=reflect.ValueOf(info).Elem()
for i:=0;i<updateS.NumField();i++{
f:=updateS.Field(i)
f_info:=infoS.Field(i)
if !f_info.IsZero(){
f.Set(reflect.Value(f_info))
}
}
return
}