FAQ
Hello.

I am writing a Google AppEngine app in Go. It has a web service that goes
to the Datastore and spits out JSON.

Now. What I want is to have the entities represented in JSON to contain the
entity key value.

Here's some pseudo-code of what I'm doing.
----------------------------------------------------------------
type Hum struct {
UID string
}

hums := make([]Hum, 0, 10)
if _, err := q.GetAll(c, &hums); err != nil {
fmt.Printf("error")
}
b, err := json.Marshal(hums);
if err != nil {
fmt.Printf("error")
}
w.Write([]byte(r.FormValue("jsoncallback")))
w.Write([]byte("("))
w.Write(b)
w.Write([]byte(")"))
----------------------------------------------------------------

So if I want the entity Datastore Key ID for each Hum entity - that is
where I'm lost.

Guessing I may have to put a Key property in the Hum struct maybe?

Any suggestions appreciated.

--

Search Discussions

  • Daniel Combs at Dec 17, 2012 at 5:02 am
    After some granular keyword search - I found my answer.

    Highlight from the link I found.

    - "intID is an internal property of a Key not the struct, and is accessible
    through a getter:"
    - "One way to get around this is to create a viewmodel struct that has both
    your post and key info "

    http://stackoverflow.com/questions/9956342/golang-gae-intid-in-struct-for-mustache


    On Sunday, December 16, 2012 10:37:58 PM UTC-5, Daniel Combs wrote:

    Hello.

    I am writing a Google AppEngine app in Go. It has a web service that goes
    to the Datastore and spits out JSON.

    Now. What I want is to have the entities represented in JSON to contain
    the entity key value.

    Here's some pseudo-code of what I'm doing.
    ----------------------------------------------------------------
    type Hum struct {
    UID string
    }

    hums := make([]Hum, 0, 10)
    if _, err := q.GetAll(c, &hums); err != nil {
    fmt.Printf("error")
    }
    b, err := json.Marshal(hums);
    if err != nil {
    fmt.Printf("error")
    }
    w.Write([]byte(r.FormValue("jsoncallback")))
    w.Write([]byte("("))
    w.Write(b)
    w.Write([]byte(")"))
    ----------------------------------------------------------------

    So if I want the entity Datastore Key ID for each Hum entity - that is
    where I'm lost.

    Guessing I may have to put a Key property in the Hum struct maybe?

    Any suggestions appreciated.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 17, '12 at 4:34a
activeDec 17, '12 at 5:02a
posts2
users1
websitegolang.org

1 user in discussion

Daniel Combs: 2 posts

People

Translate

site design / logo © 2022 Grokbase