本文整理汇总了Golang中google/golang.org/appengine/datastore.LoadStruct函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadStruct函数的具体用法?Golang LoadStruct怎么用?Golang LoadStruct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadStruct函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Load
func (t *Task) Load(ps []datastore.Property) error {
err := datastore.LoadStruct(&t.Assignment, ps)
if err != nil {
if _, ok := err.(*datastore.ErrFieldMismatch); !ok {
return err
}
}
err = datastore.LoadStruct(&t.SkillWeights, ps)
if err != nil {
if _, ok := err.(*datastore.ErrFieldMismatch); !ok {
return err
}
}
for _, p := range ps {
switch p.Name {
case "Templates":
if err := gob.NewDecoder(bytes.NewReader(p.Value.([]byte))).Decode(&t.Templates); err != nil {
return err
}
case "Tasker":
t.Tasker = p.Value.(int64)
case "Languages":
t.Languages = strings.Split(p.Value.(string), " ")
}
}
return nil
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:28,代码来源:task.go
示例2: Load
func (ac *AppConfig) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(ac, ps); err != nil {
return err
}
return nil
}
开发者ID:sinmetal,项目名称:sinmetalcraft,代码行数:7,代码来源:appconfig.go
示例3: Load
func (v *ValueGAE) Load(c <-chan datastore.Property) error {
if err := datastore.LoadStruct(v, c); err != nil {
return err
}
StoreValueBytesRead <- len(v.Value)
return nil
}
开发者ID:hanslovsky,项目名称:dvid,代码行数:7,代码来源:appengine.go
示例4: Load
func (c *DefaultClient) Load(ps []datastore.Property) error {
var p datastore.Property
for i := 0; i < len(ps); i++ {
p = ps[i]
switch p.Name {
case "Id":
if p.Value != nil {
c.Id = p.Value.(string)
}
case "Secret":
if p.Value != nil {
c.Secret = p.Value.(string)
}
case "RedirectUrl":
if p.Value != nil {
c.RedirectUri = p.Value.(string)
}
case "UserData":
c.UserData = nil
}
}
if err := datastore.LoadStruct(c, ps); err != nil {
return err
}
return nil
}
开发者ID:imtheoperator,项目名称:osin-datastore,代码行数:28,代码来源:client.go
示例5: Load
// Load implements the datastore PropertyLoadSaver imterface
func (j *job) Load(props []datastore.Property) error {
datastore.LoadStruct(j, props)
j.common.Load(props)
for _, prop := range props {
switch prop.Name {
case "job_spec":
payload := bytes.NewBuffer(prop.Value.([]byte))
enc := gob.NewDecoder(payload)
if err := enc.Decode(&j.JobSpec); err != nil {
return err
}
}
}
// jobSpec might be nil if it can't be gob encoded
// create instance from name if so
if j.JobSpec == nil {
jobSpec, err := CreateJobInstance(j.JobName)
if err != nil {
return err
}
j.JobSpec = jobSpec
}
return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:28,代码来源:job.go
示例6: TestPutPropertyLoadSaver
func TestPutPropertyLoadSaver(t *testing.T) {
c, closeFunc := NewContext(t)
defer closeFunc()
type testEntity struct {
IntVal int
}
te := &testEntity{2}
pl, err := datastore.SaveStruct(te)
if err != nil {
t.Fatal(err)
}
keys := []*datastore.Key{datastore.NewKey(c, "Test", "", 1, nil)}
pls := datastore.PropertyList(pl)
if _, err := nds.PutMulti(c, keys,
[]datastore.PropertyLoadSaver{&pls}); err != nil {
t.Fatal(err)
}
getPl := datastore.PropertyList{}
if err := nds.GetMulti(c,
keys, []datastore.PropertyLoadSaver{&getPl}); err != nil {
t.Fatal(err)
}
getTe := &testEntity{}
if err := datastore.LoadStruct(getTe, getPl); err != nil {
t.Fatal(err)
}
if te.IntVal != getTe.IntVal {
t.Fatal("expected same IntVal", getTe.IntVal)
}
}
开发者ID:zeekay,项目名称:nds,代码行数:35,代码来源:put_test.go
示例7: Load
// Load is google store Question struct loader
func (data *GamerData) Load(p []datastore.Property) error {
if err := datastore.LoadStruct(data, p); err != nil {
return err
}
data.Gamer = new(Gamer)
return json.Unmarshal([]byte(data.GamerBlob), data.Gamer)
}
开发者ID:juananpe,项目名称:QuestagBot,代码行数:8,代码来源:questagbot.go
示例8: Load
//Load fulfills the PropertyLoadSaver interface
func (linkTweet *LinkTweet) Load(in <-chan datastore.Property) error {
propertyList := []datastore.Property{}
for x := range in {
propertyList = append(propertyList, x)
}
if err := datastore.LoadStruct(linkTweet, propertyList); err != nil {
return err
}
return nil
}
开发者ID:AndyNortrup,项目名称:TweetHarvest,代码行数:11,代码来源:link-tweet.go
示例9: TestLoadSaveStruct
func TestLoadSaveStruct(t *testing.T) {
type testEntity struct {
IntValue int `datastore:",noindex"`
StringValue string
MultipleValue []int64
}
te := testEntity{10, "ten", []int64{1, 2, 3}}
pl, err := datastore.SaveStruct(&te)
if err != nil {
t.Fatal(err)
}
tests := []struct {
name string
value interface{}
noIndex bool
multiple bool
}{
{"IntValue", int64(10), true, false},
{"StringValue", "ten", false, false},
{"MultipleValue", int64(1), false, true},
{"MultipleValue", int64(2), false, true},
{"MultipleValue", int64(3), false, true},
}
for i, test := range tests {
prop := pl[i]
if prop.Name != test.name {
t.Fatal("incorrect name")
}
if prop.Value != test.value {
t.Fatalf("incorrect value required %+v got %+v",
prop.Value, test.value)
}
if prop.NoIndex != test.noIndex {
t.Fatal("incorrect no index")
}
if prop.Multiple != test.multiple {
t.Fatal("incorrect multiple flag")
}
}
loadTestEntity := testEntity{}
if err := datastore.LoadStruct(&loadTestEntity, pl); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(te, loadTestEntity) {
t.Fatal("entities not equal")
}
}
开发者ID:jongillham,项目名称:nds,代码行数:52,代码来源:nds_test.go
示例10: Load
// Load implements the datastore PropertyLoadSaver imterface
func (n *namespace) Load(props []datastore.Property) error {
datastore.LoadStruct(n, props)
n.common.Load(props)
for _, prop := range props {
switch prop.Name {
case "query":
n.Query = &Query{}
if err := n.Query.GobDecode(prop.Value.([]byte)); err != nil {
return err
}
}
}
return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:17,代码来源:namespace.go
示例11: setValue
func setValue(val reflect.Value, pl datastore.PropertyList) error {
if reflect.PtrTo(val.Type()).Implements(typeOfPropertyLoadSaver) {
val = val.Addr()
}
if pls, ok := val.Interface().(datastore.PropertyLoadSaver); ok {
return pls.Load(pl)
}
if val.Kind() == reflect.Struct {
val = val.Addr()
}
if val.Kind() == reflect.Ptr && val.Type().Elem().Kind() == reflect.Struct && val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return datastore.LoadStruct(val.Interface(), pl)
}
开发者ID:jongillham,项目名称:nds,代码行数:18,代码来源:nds.go
示例12: Get
// Get stores the application configuration in the variable pointed to by conf.
func Get(ctx context.Context, conf interface{}) error {
switch t := ctx.Value(internal.ConfigContextKey).(type) {
case *datastore.PropertyList:
switch confT := conf.(type) {
case *Config:
*confT = Config(*t)
return nil
default:
err := datastore.LoadStruct(conf, *t)
if _, ok := err.(*datastore.ErrFieldMismatch); ok {
return nil
} else {
return err
}
}
case error:
return t
default:
return ErrNotInConfigContext
}
}
开发者ID:the-information,项目名称:ori,代码行数:24,代码来源:config.go
示例13: Load
/* datastore */
func (c *common) Load(props []datastore.Property) error {
datastore.LoadStruct(c, props)
c.Counters = make(map[string]int64)
for _, prop := range props {
switch prop.Name {
case "query":
c.Query = &Query{}
if err := c.Query.GobDecode(prop.Value.([]byte)); err != nil {
return err
}
default:
if strings.HasPrefix(prop.Name, "counters.") {
key := prop.Name[9:len(prop.Name)]
c.Counters[key] = prop.Value.(int64)
}
}
}
c.startTime = getTime()
return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:24,代码来源:common.go
示例14: Load
// Load implements the datastore PropertyLoadSaver imterface
func (it *iterator) Load(props []datastore.Property) error {
datastore.LoadStruct(it, props)
it.common.Load(props)
return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:6,代码来源:iterator.go
示例15: Load
func (r *RefreshToken) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(r, ps); err != nil {
return err
}
return nil
}
开发者ID:imtheoperator,项目名称:osin-datastore,代码行数:6,代码来源:refresh_token.go
示例16: Load
func (ad *AuthorizeData) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(ad, ps); err != nil {
return err
}
return nil
}
开发者ID:imtheoperator,项目名称:osin-datastore,代码行数:6,代码来源:authorizedata.go
示例17: Load
// Load implements the datastore PropertyLoadSaver imterface
func (s *shard) Load(props []datastore.Property) error {
datastore.LoadStruct(s, props)
s.common.Load(props)
return nil
}
开发者ID:CaptainCodeman,项目名称:datastore-mapper,代码行数:6,代码来源:shard.go
示例18: LoadStruct
// LoadStruct wraps datastore.LoadStruct
func (d *Driver) LoadStruct(dst interface{}, props []datastore.Property) error {
// TODO: d.logOps
return datastore.LoadStruct(dst, props)
}
开发者ID:speedland,项目名称:service,代码行数:5,代码来源:datastore.go
注:本文中的google/golang.org/appengine/datastore.LoadStruct函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论