私は持っている
http://localhost:8080/?key=ahFkZXZ-ZGV2LWVkdW5hdGlvbnIOCxIIVXNlckluZm8YLAw
次の方法についてお聞きしたいです。
- 「キー」をデコードして
*datastore.Key - そして、それを使用してエンティティを取得します。
ご協力いただきありがとうございます!
私は持っている
http://localhost:8080/?key=ahFkZXZ-ZGV2LWVkdW5hdGlvbnIOCxIIVXNlckluZm8YLAw
次の方法についてお聞きしたいです。
*datastore.Keyご協力いただきありがとうございます!
最初に:この場合に必要なパッケージを検討する必要があります。GETから値を読み取ろうとしているので、URLおそらく からの関数が必要ですnet/http。特に:FormValue(key string)戻り値GETとPOSTパラメーター。
appengine/datastore2番目:ドキュメントを開き、次のことを行う関数を見つけます:
stringaを a にデコード*datastore.Key( DecodeKey(encoded string) )今では本当に簡単なことです:
func home(w http.Response, r *http.Request) {
c := appengine.NewContext(r)
// Get the key from the URL
keyURL := r.FormValue("key")
// Decode the key
key, err := datastore.DecodeKey(keyURL)
if err != nil { // Couldn't decode the key
// Do some error handling
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Get the key and load it into "data"
var data Data
err = datastore.Get(c, key, data)
if err != nil { // Couldn't find the entity
// Do some error handling
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}