0
存儲在PostgreSQL中的數據:The <b>Argentine Army</b> is
。數據類型:"content" text COLLATE "default"
。Golang + PostgreSQL - 如何打印確切的查詢沒有轉義的HTML標籤?
當打印通過Golang,它成爲The <b>Argentine Army</b> is
我需要打印和PostgreSQL確切的數據沒有逃脫的HTML標籤。我不確定這是Go還是PostgreSQL問題。下面
是我Golang代碼:
package main
import (
"database/sql"
"github.com/labstack/echo"
_ "github.com/lib/pq"
"html/template"
"io"
"log"
"net/http"
)
// type Gallery struct here
// type Template struct & function here
func main() {
e := echo.New()
// DB connection here
// Parse template & render here
e.Get("/", func(c *echo.Context) error {
rows, err := db.Query("SELECT uri, title, content FROM gallery WHERE id=123")
// Handle error here
gallery := []Gallery{}
for rows.Next() {
b := Gallery{}
err := rows.Scan(&b.Uri, &b.Title, &b.Content)
// Handle error here
gallery = append(gallery, b)
}
return c.Render(http.StatusOK, "onlytestingtpl", gallery[0])
})
e.Run(":4444")
}
它來自'unsafe'包嗎?因爲我使用Echo框架,我應該在哪裏放置代碼? –
它來自html/template包 - 我不熟悉Echo框架。我剛剛命名了我在「不安全」答案中寫的函數。你應該可以把任何地方放到真正的地方,並將你的內容字符串傳遞給它。 – rebelbass
非常感謝。我仍在努力尋找解決方案。我正在使用'text/template'作爲臨時解決方法。 –