duanbiyi7319 2012-12-07 09:32 采纳率: 100%
浏览 53

如何在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.

  • 写回答

3条回答 默认 最新

  • dongyu2300 2012-12-07 18:49
    关注

    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?

    评论

报告相同问题?