I'm refactoring server side logic in Go, but there is error that I can't resolve.
・client: react/axios
・api: golang/gin
・web-server: nginx
・db: mysql
・container: docker
・ci-tool: travis
・deploy: aws elastic beanstalk
service.go
func GetSingleArticleService(c *gin.Context, db *sql.DB) Article {
article, rows := dao.GetSingleArticleDao(c, db)
for rows.Next() {
imageName := ImageName{}
err := rows.Scan(&imageName.NAME)
if err != nil {
panic(err.Error())
}
// error occurs here
article.IMAGENAMES = append(article.IMAGENAMES, imageName)
}
return article
}
dao.go
func GetSingleArticleDao(c *gin.Context, db *sql.DB) (Article, *sql.Rows) {
id := c.Params.ByName("id")
article := Article{}
errArticle := db.QueryRow("SELECT * FROM articles WHERE id = ?", id).Scan(&article.ID, &article.UUID, &article.TITLE, &article.CONTENT)
if errArticle != nil {
panic(errArticle.Error())
}
rows, errImage := db.Query("SELECT image_name FROM images WHERE article_uuid = ?", article.UUID)
if errImage != nil {
panic(errImage.Error())
}
return article, rows
}
I expect there is no compile error, but the actual is not. There is error at service.go.
cannot use imageName (type ImageName) as type dao.ImageName in append