how to put struct data in datastore in go-lang: //Struct is created.
type UserLogin struct{
userName string
passWord string
}
//values assigned
p1 := UserLogin{"poonam", "mumbai123"} p2 := UserLogin{passWord:"mumbai321", userName:"abcd"}
Now how to store/put/save and get above p1, p2 into datastore?
change struct to:
type UserLogin struct{
UserName string
PassWord string
}
needs to be public fields
storing:
c := appengine.NewContext(r)
p1 := UserLogin{"poonam", "mumbai123"}
key := datastore.NewKey(c, "UserLogin",p1.UserName, 0, nil)
datastore.Put(c, key,&p1)
reading:
c := appengine.NewContext(r)
key := datastore.NewKey(c, "UserLogin", "", userName, nil)
var ul UserLogin
err := datastore.Get(c, key, &ul)
where r is the *http.Request also you need todo something with error,