第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go中的HTML模板-插入html作為pipleline的值

Go中的HTML模板-插入html作為pipleline的值

Go
躍然一笑 2021-05-10 16:43:02
我正在使用Go模板輸出html,并通過管道插入一些值。事情是原始HTML值之一,我不想對其進行轉(zhuǎn)義。但是當執(zhí)行模板時,將對其進行轉(zhuǎn)義。這是代碼package main import (    "fmt"    "io/ioutil"    "log"    "net/http"    "html/template"    "encoding/xml")type RSS struct {    XMLName xml.Name `xml:"rss"`    Items Items `xml:"channel"`}type Items struct {    XMLName xml.Name `xml:"channel"`    ItemList []Item `xml:"item"`}type Item struct {    Title string `xml:"title"`    Link string `xml:"link"`    Description string `xml:"description"`}func main() {    res, err := http.Get("http://news.google.com/news?hl=en&gl=us&q=samsung&um=1&ie=UTF-8&output=rss")    if err != nil {        log.Fatal(err)    }    asText, err := ioutil.ReadAll(res.Body)    if err != nil {        log.Fatal(err)    }    var i RSS    err = xml.Unmarshal([]byte(asText), &i)    if err != nil {        log.Fatal(err)      }    res.Body.Close()    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {              handler(w, r, i)       })    http.ListenAndServe(":8080", nil)}func handler(w http.ResponseWriter, r *http.Request, i RSS) {    t, _ := template.ParseFiles("index.html")    t.Execute(w, i.Items)}這是HTML:<html>    <head>    </head>    <body>        {{range .ItemList}}        <div class="news-item">            <p>                <a href="{{.Link}}">{{.Title}}</a>            </p>            <p>{{.Description}}</p>        </div>        {{end}}    </body></html>輸出看起來像這樣:<div class="news-item">            <p>                <a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNFd-5CF7Rwy7sjNZ2-fSOLkO6ri5g&amp;url=http://www.pehub.com/186539/what-apple-might-learn-samsung/">What Apple Might Learn from Samsung - Private Equity Hub (press release)</a>            </p>        </div>說明是轉(zhuǎn)義的html,我希望它是常規(guī)的html
查看完整描述

2 回答

?
陪伴而非守候

TA貢獻1757條經(jīng)驗 獲得超8個贊

將管道的描述字段的類型template.HTML改為string,而不是,如下所示:


type pipeObject struct {

    Description template.HTML


pipe := &pipeObject{

    template.HTML("<p>Your safe HTML</p>"),

}

相關(guān)文檔:template.HTML


查看完整回答
反對 回復 2021-05-31
?
PIPIONE

TA貢獻1829條經(jīng)驗 獲得超9個贊

將管道的描述字段的類型template.HTML改為string,而不是,如下所示:


type pipeObject struct {

    Description template.HTML


pipe := &pipeObject{

    template.HTML("<p>Your safe HTML</p>"),

}

相關(guān)文檔:template.HTML


查看完整回答
反對 回復 2021-05-31
  • 2 回答
  • 0 關(guān)注
  • 275 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號