1 回答

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
經(jīng)過一定量的實(shí)驗(yàn)后,發(fā)現(xiàn)這里是如何Save()為具有結(jié)構(gòu)的對(duì)象實(shí)現(xiàn)方法。datastore.Property 必須存儲(chǔ)持有數(shù)組[]interface{}而[]*datastore.Entity不是純數(shù)組[]*datastore.Entity:
func (p *Person) Save() ([]datastore.Property, error) {
props := []datastore.Property{
{
Name: "Name",
Value: p.Name,
},
}
var n []interface{}
for _, x := range p.Phone {
i1 := datastore.Property{Name: "Type", Value: x.Type}
i2 := datastore.Property{Name: "Number", Value: x.Number}
e := &datastore.Entity{Properties: []datastore.Property{i1, i2}}
n = append(n, e)
}
props = append(props, datastore.Property{Name:"Phone",Value:n})
return props, nil
}
- 1 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報(bào)