5

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.

2
  • Datastore? An App Engine datastore maybe? If so it would help to tag the question google-app-engine or gae-datastore. Commented Dec 7, 2012 at 16:07
  • I removed the app-engine tag as the question does not seem to be related to app engine directly. Maybe I misread the question? Commented Dec 7, 2012 at 16:16

3 Answers 3

1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot...I wasn't clear in the question i posted. I am actually creating this structure to create a Json and save it in datastore. The Json structure should be like this {"Id":"20122403","Dailypred":{"Prediction":"ABCD"}}. The problem while reading the Json is that it throws an error - "SAVE datastore: unsupported struct field type: pcg_new.DailyPrediction"..please help on this
I just did the following: var jsonBlob = []byte({"Id": "meemaw", "Prediction": "Moonpie"}), and that successfully unmarshalled to the struct I made, where the DailyPrediction struct contains the string Prediction. Is that what you're looking for?
Never mind, I see that the problem wasn't getting json to read it, but appEngine to store it. It sounds like the answer by @alphazero is more relevant, that this is not supported.
1

Not supported by the appengine.

1 Comment

It is supported by the app engine, in the sense that you can do it yourself, the libraries don't take care of it. You need to implement the interface and flatten things out.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.