H
H
hitakiri2017-10-29 20:36:37
go
hitakiri, 2017-10-29 20:36:37

How to pass html from sql query to structure with type template.HTML?

There is a structure

type NewsData struct {
  Id       int    // id новости
  Uid      int   
  Pt       int    
  Title    string // заголовок новости
  Post     template.HTML // текст новости
  Time     time.Time // время создания или изменения
}

when receiving a response from the database
var n NewsData
err := rows.Scan(&n.Id, &n.Uid, &n.Pt, &n.Title, &n.Post, &n.Time)

Gives an error message :
Scan error on column index 4: unsupported Scan, storing driver.Value type []uint8 into type *template.HTML

Changing to string type is not very convenient, because it will complicate the logic.
How can this error be avoided?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid Nikolaev, 2017-10-29
@nikonor

Describe the structure, implement Scan and Value for it.
The format of the structure is something like template.HTML + Valid bool, but I don’t know if it will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question