I stuck with an unique problem. To learn golang, I created a twitter kind of website. It has tweets and each tweets can have comments and each comment can have sub-comments.
Showing struct pd in homepage.html
Env.Tpl.ExecuteTemplate(w, "homePage.html", pd)
where pd is pagedata (I removed extra information for simplicity)
type PageData struct {
TweetView []tweets.TweetView
}
Where tweet.TweetView is
type TweetView struct {
Tweet
CV []comments.Comment
}
where comments.Comment is
type Comment struct {
TweetID int64
ParentCommentID int64
CommentID int64
CreatedAt time.Time
Name string
UserID int64
CommentMsg string
}
This works. but if I change the CV in tweetView with comment.CommentView .. template stop showing TweetView.
comment.CommentView is
type CommentView struct { Comment CC []Comment }
the new TweetView would be defined as
type TweetView struct {
Tweet
CV []comments.CommentView
}
Getting this error, when trying to make a datastore query to extract tweet object into Tweetview
err := datastore.Get(ctx, tweetKey, &tweetView[v])
datastore: flattening nested structs leads to a slice of slices: field "CV",
I think it is a limitation of golang. What should I do?
I was able to solve the problem. The problem was with datastore.Get query.
It was giving below error when I was running
err := datastore.Get(ctx, tweetKey, &tweetView[v])
datastore: flattening nested structs leads to a slice of slices: field "CV",
So what I changed the query like this
var tweetTemp Tweet
datastore.Get(ctx, tweetKey, &tweetTemp)
tweetSlice[v].Tweet = tweetTemp
Please let me know if you see problem with this approach