本文整理汇总了Golang中google/golang.org/appengine/internal/datastore.Property类的典型用法代码示例。如果您正苦于以下问题:Golang Property类的具体用法?Golang Property怎么用?Golang Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Property类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestStringMeaning
func TestStringMeaning(t *testing.T) {
var xx [4]interface{}
xx[0] = &struct {
X string
}{"xx0"}
xx[1] = &struct {
X string `datastore:",noindex"`
}{"xx1"}
xx[2] = &struct {
X []byte
}{[]byte("xx2")}
xx[3] = &struct {
X []byte `datastore:",noindex"`
}{[]byte("xx3")}
indexed := [4]bool{
true,
false,
false, // A []byte is always no-index.
false,
}
want := [4]pb.Property_Meaning{
pb.Property_NO_MEANING,
pb.Property_TEXT,
pb.Property_BLOB,
pb.Property_BLOB,
}
for i, x := range xx {
c := make(chan Property, 1)
err := SaveStruct(x, c)
if err != nil {
t.Errorf("i=%d: SaveStruct: %v", i, err)
continue
}
e, err := propertiesToProto("appID", testKey0, c)
if err != nil {
t.Errorf("i=%d: propertiesToProto: %v", i, err)
continue
}
var p *pb.Property
switch {
case indexed[i] && len(e.Property) == 1:
p = e.Property[0]
case !indexed[i] && len(e.RawProperty) == 1:
p = e.RawProperty[0]
default:
t.Errorf("i=%d: EntityProto did not have expected property slice", i)
continue
}
if got := p.GetMeaning(); got != want[i] {
t.Errorf("i=%d: meaning: got %v, want %v", i, got, want[i])
continue
}
}
}
开发者ID:proppy,项目名称:appengine,代码行数:56,代码来源:datastore_test.go
示例2: protoToEntity
func protoToEntity(src *pb.EntityProto) (*Entity, error) {
props, rawProps := src.Property, src.RawProperty
outProps := make([]Property, 0, len(props)+len(rawProps))
for {
var (
x *pb.Property
noIndex bool
)
if len(props) > 0 {
x, props = props[0], props[1:]
} else if len(rawProps) > 0 {
x, rawProps = rawProps[0], rawProps[1:]
noIndex = true
} else {
break
}
var value interface{}
if x.Meaning != nil && *x.Meaning == pb.Property_INDEX_VALUE {
value = indexValue{x.Value}
} else {
var err error
value, err = propValue(x.Value, x.GetMeaning())
if err != nil {
return nil, err
}
}
outProps = append(outProps, Property{
Name: x.GetName(),
Value: value,
NoIndex: noIndex,
Multiple: x.GetMultiple(),
})
}
var key *Key
if src.Key != nil {
// Ignore any error, since nested entity values
// are allowed to have an invalid key.
key, _ = protoToKey(src.Key)
}
return &Entity{key, outProps}, nil
}
开发者ID:golang,项目名称:gddo,代码行数:43,代码来源:load.go
示例3: protoToProperties
func protoToProperties(dst chan<- Property, errc chan<- error, src *pb.EntityProto) {
defer close(dst)
props, rawProps := src.Property, src.RawProperty
for {
var (
x *pb.Property
noIndex bool
)
if len(props) > 0 {
x, props = props[0], props[1:]
} else if len(rawProps) > 0 {
x, rawProps = rawProps[0], rawProps[1:]
noIndex = true
} else {
break
}
var value interface{}
if x.Meaning != nil && *x.Meaning == pb.Property_INDEX_VALUE {
value = indexValue{x.Value}
} else {
var err error
value, err = propValue(x.Value, x.GetMeaning())
if err != nil {
errc <- err
return
}
}
dst <- Property{
Name: x.GetName(),
Value: value,
NoIndex: noIndex,
Multiple: x.GetMultiple(),
}
}
errc <- nil
}
开发者ID:proppy,项目名称:appengine,代码行数:37,代码来源:load.go
示例4: protoToProperties
func protoToProperties(src *pb.EntityProto) ([]Property, error) {
props, rawProps := src.Property, src.RawProperty
out := make([]Property, 0, len(props)+len(rawProps))
for {
var (
x *pb.Property
noIndex bool
)
if len(props) > 0 {
x, props = props[0], props[1:]
} else if len(rawProps) > 0 {
x, rawProps = rawProps[0], rawProps[1:]
noIndex = true
} else {
break
}
var value interface{}
if x.Meaning != nil && *x.Meaning == pb.Property_INDEX_VALUE {
value = indexValue{x.Value}
} else {
var err error
value, err = propValue(x.Value, x.GetMeaning())
if err != nil {
return nil, err
}
}
out = append(out, Property{
Name: x.GetName(),
Value: value,
NoIndex: noIndex,
Multiple: x.GetMultiple(),
})
}
return out, nil
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:36,代码来源:load.go
注:本文中的google/golang.org/appengine/internal/datastore.Property类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论