func NewKey(c appengine.Context,kind,stringID string,intID int64,parent *Key) *Key
文档说:
NewKey creates a new key. kind cannot be empty. Either one or both of
stringID and intID must be zero. If both are zero,the key
returned is incomplete. parent must either be a complete key or nil.
字符串的零是什么?
我试过0和nil,我得到错误像:
cannot use nil as type string in function argument
那是 ”” :
var s string fmt.Println(s=="") // prints "true"
字符串不能为nil(但是*字符串可以)。
你可以简单测试
if stringId=="" {
要在stringID中传递零字符串,请使用
k := NewKey(c,"kind","",p)
When memory is allocated to store a value,either through a
declaration or a call of make or new,and no explicit initialization
is provided,the memory is given a default initialization. Each
element of such a value is set to the zero value for its type: false
for booleans,0 for integers,0.0 for floats,“” for strings,and nil for pointers,functions,interfaces,slices,channels,and maps.