Raj
Raj

Reputation: 59

How to store a struct inside a struct in go?

I have two structure (New and DailyPrediction) with DailyPrediction structure as one of the entity of New structure:

type New struct {
    Id string
    DailyPrediction
}

type DailyPrediction struct {
    Prediction string
}

I am unable to read (or) write the structure new in the datastore. It would be helpful if someone can help me on this.

Upvotes: 5

Views: 781

Answers (3)

Dewey
Dewey

Reputation: 776

Just to update this post for future readers ... this info is OLD ... nested structs are now supported

Upvotes: 0

alphazero
alphazero

Reputation: 27244

Not supported by the appengine.

Upvotes: 1

Derek
Derek

Reputation: 3137

It is unclear to me from your question what exactly you are doing with the struct, and in what way it is failing. However, while you are embedding the DailyPrediction struct in your new struct by not giving it a name, it still needs to be initialized. You can see details of how to do that here: http://golang.org/doc/effective_go.html#embedding

For example, in order to initialize your New struct, you may use a line like this:

    n := New{"foo", DailyPrediction{"bar"}}

Could that be what was missing?

Upvotes: 1

Related Questions