From 42e7acc965daea755a84064f68e4eebf3e3b2e11 Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Thu, 28 Jan 2021 18:12:10 -0800 Subject: nil pointers ......... --- outboxGet.go | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'outboxGet.go') diff --git a/outboxGet.go b/outboxGet.go index 073a4bb..a42a3d7 100644 --- a/outboxGet.go +++ b/outboxGet.go @@ -93,7 +93,6 @@ func GetCollectionFromPath(db *sql.DB, path string) Collection { func GetObjectFromPath(db *sql.DB, path string) ObjectBase{ var nObj ObjectBase - var result []ObjectBase query := `select id, name, content, type, published, attributedto, attachment, preview, actor from activitystream where id=$1 order by published desc` @@ -102,37 +101,30 @@ func GetObjectFromPath(db *sql.DB, path string) ObjectBase{ CheckError(err, "error query collection path from db") defer rows.Close() + rows.Next() + var attachID string + var previewID string - for rows.Next(){ - var post ObjectBase - var attachID string - var previewID string - - var nActor Actor - post.Actor = &nActor - - err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.AttributedTo, &attachID, &previewID, &post.Actor.Id) - - CheckError(err, "error scan object into post struct from path") - - - var postCnt int - var imgCnt int - post.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, post) + var nActor Actor + nObj.Actor = &nActor + + err = rows.Scan(&nObj.Id, &nObj.Name, &nObj.Content, &nObj.Type, &nObj.Published, &nObj.AttributedTo, &attachID, &previewID, &nObj.Actor.Id) + + CheckError(err, "error scan object into post struct from path") - post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesDBCount(db, post) + var postCnt int + var imgCnt int - post.Replies.TotalItems = post.Replies.TotalItems + postCnt - post.Replies.TotalImgs = post.Replies.TotalImgs + imgCnt + nObj.Replies, postCnt, imgCnt = GetObjectRepliesDB(db, nObj) - post.Attachment = GetObjectAttachment(db, attachID) + nObj.Replies.TotalItems, nObj.Replies.TotalImgs = GetObjectRepliesDBCount(db, nObj) - post.Preview = GetObjectPreview(db, previewID) + nObj.Replies.TotalItems = nObj.Replies.TotalItems + postCnt + nObj.Replies.TotalImgs = nObj.Replies.TotalImgs + imgCnt - result = append(result, post) - } + nObj.Attachment = GetObjectAttachment(db, attachID) - nObj = result[0] + nObj.Preview = GetObjectPreview(db, previewID) return nObj } -- cgit v1.2.3