Go with GAE hat ein Objekt im Datenspeicher gespeichert. Wenn es zurückkommt, hat das Objekt leere Mitglieder

Ich versuche mit GAE zu lernen. Ich habe 2 Handler erstellt. Eines zum Speichern eines Objekts im Datenspeicher und das andere zum Abrufen und Ausgeben auf dem Bildschirm. Das Problem ist, dass beim Abrufen des UserAccount-Objekts aus dem Datenspeicher alle Werte im Objekt gelöscht werden.

Jede Hilfe wäre dankbar.

Ausgabe:

a/c count: 2 val: core.UserAccount{idString:"", deviceId:""} val: core.UserAccount{idString:"", deviceId:""}

type UserAccount struct {
    idString string
    deviceId string
}

func create_account(w http.ResponseWriter, r *http.Request) {

    c := appengine.NewContext(r)

        idstr := "ABCDEFGH"
        devId := r.FormValue("deviceId")

        newAccount := UserAccount{ idString: idstr, deviceId: devId,}

        key := datastore.NewIncompleteKey(c, "UserAccount", nil)
        _, err := datastore.Put(c, key, &newAccount)
        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
            return
    }

    fmt.Fprintf(w, "val: %#v \n", newAccount)
}

func get_info(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)

    q := datastore.NewQuery("UserAccount")
    accounts := make([]UserAccount, 0, 10)
    if _, err := q.GetAll(c, &accounts); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    fmt.Fprintf(w, "a/c count: %v \n", len(accounts))

    for i := 0; i < len(accounts); i++ {
        fmt.Fprintf(w, "val: %#v \n", accounts[i])
    }
}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage