本文整理汇总了Golang中google/golang.org/appengine/datastore.LoadStruct函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadStruct函数的具体用法?Golang LoadStruct怎么用?Golang LoadStruct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadStruct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: Load
func (ac *AppConfig) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(ac, ps); err != nil {
return err
}
return nil
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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")
}
}
示例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
}
示例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)
}
示例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
}
}
示例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
}
示例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
}
示例15: Load
func (r *RefreshToken) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(r, ps); err != nil {
return err
}
return nil
}