Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
func (ac *AppConfig) Load(ps []datastore.Property) error {
	if err := datastore.LoadStruct(ac, ps); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
// 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
}
Exemplo n.º 6
0
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)
	}
}
Exemplo n.º 7
0
// 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)
}
Exemplo n.º 8
0
//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
}
Exemplo n.º 9
0
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")
	}
}
Exemplo n.º 10
0
// 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
}
Exemplo n.º 11
0
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)
}
Exemplo n.º 12
0
// 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
	}

}
Exemplo n.º 13
0
/* 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
}
Exemplo n.º 14
0
// Load implements the datastore PropertyLoadSaver imterface
func (it *iterator) Load(props []datastore.Property) error {
	datastore.LoadStruct(it, props)
	it.common.Load(props)
	return nil
}
Exemplo n.º 15
0
func (r *RefreshToken) Load(ps []datastore.Property) error {
	if err := datastore.LoadStruct(r, ps); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 16
0
func (ad *AuthorizeData) Load(ps []datastore.Property) error {
	if err := datastore.LoadStruct(ad, ps); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 17
0
// Load implements the datastore PropertyLoadSaver imterface
func (s *shard) Load(props []datastore.Property) error {
	datastore.LoadStruct(s, props)
	s.common.Load(props)
	return nil
}
Exemplo n.º 18
0
// LoadStruct wraps datastore.LoadStruct
func (d *Driver) LoadStruct(dst interface{}, props []datastore.Property) error {
	// TODO: d.logOps
	return datastore.LoadStruct(dst, props)
}