// Get is a convience method for retrieveing an entity from the ds. func Get(c appengine.Context, id string) (up *Profile, err error) { up = &Profile{} key := datastore.NewKey(c, "AuthProfile", id, 0, nil) err = ds.Get(c, key, up) up.Key = key up.Decode() return }
// Get is a convience method for retrieveing an entity foom the store. func Get(c appengine.Context, id string) (u *User, err error) { u = &User{} key := datastore.NewKey(c, "User", id, 0, nil) err = ds.Get(c, key, u) u.Key = key u.Decode() return u, err }
func Get(c context.Context, token string) (e *Token, err error) { e = &Token{} k := datastore.NewKey(c, "UserToken", token, 0, nil) if err = ds.Get(c, k, e); err != nil { return nil, err } e.Key = k e.Token = k.StringID() return }
// Get retieves a Config using the string key. If Config is not found // it returns ds/error.ErrNoSuchEntity. func Get(c appengine.Context, key string) (cnfg *Config, err error) { cnfg = new(Config) cnfg.SetKey(c, key) err = ds.Get(c, cnfg.Key, cnfg) m := make(map[string]string) err = json.Unmarshal(cnfg.ValuesJSON, &m) cnfg.Values = m return }
// Current checks the requesting User's session to see if they have an // account. If they do, the provided User struct is populated with the // information that is saved in the datastore. If they don't an error is // returned. func Current(r *http.Request) (*User, error) { id, _ := CurrentUserID(r) if id != "" { c := context.NewContext(r) u := new(User) key := datastore.NewKey(c, "User", id, 0, nil) err := ds.Get(c, key, u) u.Key = key return u, err } return nil, ErrNoLoggedInUser }
func get(c appengine.Context, key *datastore.Key) (p *Perm, err error) { p = &Perm{} err = ds.Get(c, key, p) return }
func TestGet(t *testing.T) { c := context.NewContext(nil) defer tearDown() // Save it. u := New("Google", "http://plus.google.com") u.ID = "12345" u.Person = &person.Person{ Name: &person.PersonName{ GivenName: "Barack", FamilyName: "Obama", }, } key := newKey(c, "google", "12345") u.Key = key err := u.Put(c) if err != nil { t.Errorf(`err: %q, want nil`, err) } // Get it. u2 := &Profile{} id := "google|12345" key = datastore.NewKey(c, "AuthProfile", id, 0, nil) err = ds.Get(c, key, u2) if err != nil { t.Errorf(`err: %q, want nil`, err) } u2, err = Get(c, id) if err != nil { t.Errorf(`err: %v, want nil`, err) } if u2.ID != "12345" { t.Errorf(`u2.ID: %v, want "1"`, u2.ID) } if u2.Key.StringID() != "google|12345" { t.Errorf(`uKey.StringID(): %v, want "google|12345"`, u2.Key.StringID()) } if x := u2.ProviderURL; x != "http://plus.google.com" { t.Errorf(`u2.ProviderURL: %v, want %s`, x, "http://plus.google.com") } if x := u2.Person.ID; x != "12345" { t.Errorf(`u2.Person.ID: %v, want %s`, x, "12345") } if x := u2.Person.Name.GivenName; x != "Barack" { t.Errorf(`u2.Person.Name.GivenName: %v, want %s`, x, "Barack") } if x := u2.Person.Provider.Name; x != "Google" { t.Errorf(`u2.Person.Provider.Name: %v, want %s`, x, "Google") } if x := u2.Person.Provider.URL; x != "http://plus.google.com" { t.Errorf(`u2.Person.Provider.URL: %v, want %s`, x, "http://plus.google.com") } if x := u2.Person.Kind; x != "google#person" { t.Errorf(`u2.Person.Kind: %v, want %s`, x, "google#person") } if u2.Person.Created != u2.Created.UnixNano()/1000000 { t.Errorf(`u2.Created: %v, want %v`, u2.Person.Created, u2.Created.UnixNano()/1000000) } if u2.Person.Updated != u2.Updated.UnixNano()/1000000 { t.Errorf(`u2.Updated: %v, want %v`, u2.Person.Updated, u2.Updated.UnixNano()/1000000) } }