Export returns the comment as a map for JSON output.
()
| 186 | |
| 187 | // Export returns the comment as a map for JSON output. |
| 188 | func (c DiscussionComment) Export() map[string]interface{} { |
| 189 | replies := make([]interface{}, len(c.Replies.Comments)) |
| 190 | for i, r := range c.Replies.Comments { |
| 191 | replies[i] = r.ExportReply() |
| 192 | } |
| 193 | reactions := make([]interface{}, len(c.ReactionGroups)) |
| 194 | for i, rg := range c.ReactionGroups { |
| 195 | reactions[i] = rg.Export() |
| 196 | } |
| 197 | repliesMap := map[string]interface{}{ |
| 198 | "totalCount": c.Replies.TotalCount, |
| 199 | "nodes": replies, |
| 200 | } |
| 201 | if c.Replies.Cursor != "" { |
| 202 | repliesMap["cursor"] = c.Replies.Cursor |
| 203 | } |
| 204 | if c.Replies.NextCursor != "" { |
| 205 | repliesMap["next"] = c.Replies.NextCursor |
| 206 | } |
| 207 | return map[string]interface{}{ |
| 208 | "id": c.ID, |
| 209 | "url": c.URL, |
| 210 | "author": c.Author.Export(), |
| 211 | "body": c.Body, |
| 212 | "createdAt": c.CreatedAt, |
| 213 | "isAnswer": c.IsAnswer, |
| 214 | "upvoteCount": c.UpvoteCount, |
| 215 | "reactionGroups": reactions, |
| 216 | "replies": repliesMap, |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // ExportReply returns a reply as a map for JSON output, without nested replies. |
| 221 | func (c DiscussionComment) ExportReply() map[string]interface{} { |
nothing calls this directly
no test coverage detected