我的單元測(cè)試失敗并顯示以下消息:&errors.errorString{s:"datastore: unsupported struct field type: sus.Version"}我有一個(gè)測(cè)試結(jié)構(gòu)類型,我試圖將其保存到 GAE 數(shù)據(jù)存儲(chǔ):type foo struct{ sus.Version}其中 sus.Version 是接口:type Version interface{ GetVersion() int getVersion() int incrementVersion() decrementVersion() }我嘗試使用兩個(gè)版本實(shí)現(xiàn)運(yùn)行我的測(cè)試,首先它只是一個(gè) int 的別名:type version int其次作為結(jié)構(gòu):type version struct{ val int}在 Version 接口方法被賦予接收器類型的地方(v *version),它需要是一個(gè)指針,因此遞減和遞增實(shí)際上更新它們被調(diào)用的版本,而不僅僅是一個(gè)副本。我不確定為什么這不起作用,可能是因?yàn)樗且粋€(gè)匿名字段?或者也許是因?yàn)樗侵赶?int 或 struct 而不是實(shí)際的 int 或 struct 的指針?
為什么 GAE 數(shù)據(jù)存儲(chǔ)不支持簡(jiǎn)單的結(jié)構(gòu)字段類型?
哆啦的時(shí)光機(jī)
2021-10-18 13:56:05