时间:2021-06-16 08:23:02 | 栏目:Golang | 点击:次
golang修改结构体中的切片值,直接传结构体地址就可以
package main import "fmt" type rspInfo struct { KeyWords string `json:"key_words"` Value []string `json:"value"` } func setSlice(te *[]string){ str := "12" *te = append(*te,str) } //结构提传指针 func setStruc(rsp *rspInfo){ str := "12" te := make([]string,0) te = append(te,str) te = append(te,str) rsp.KeyWords = "12" rsp.Value = te } func main() { //test := make([]string,0) //setSlice(&test) var rsp rspInfo setStruc(&rsp) fmt.Println(rsp) }