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

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

模板和自定義功能;恐慌:功能未定義

模板和自定義功能;恐慌:功能未定義

Go
慕無忌1623718 2021-06-08 13:19:46
使用html/template我試圖在模板中使用我自己的功能之一。不幸的是,我無法使用 go 模板的函數(shù)映射功能。我得到的只是以下錯誤:% go run test.gopanic: template: tmpl.html:5: function "humanSize" not defined[...]簡化的測試用例如下 ( test.go):package mainimport (    "html/template"    "io/ioutil"    "net/http"    "strconv")var funcMap = template.FuncMap{    "humanSize": humanSize,}var tmplGet = template.Must(template.ParseFiles("tmpl.html")).Funcs(funcMap)func humanSize(s int64) string {    return strconv.FormatInt(s/int64(1000), 10) + " KB"}func getPageHandler(w http.ResponseWriter, r *http.Request) {    files, _ := ioutil.ReadDir(".")    if err := tmplGet.Execute(w, files); err != nil {        http.Error(w, err.Error(), http.StatusInternalServerError)    }}func main() {    http.HandleFunc("/", getPageHandler)    http.ListenAndServe(":8080", nil)}我有以下簡單模板 ( tmpl.html):<html><body>    {{range .}}    <div>        <span>{{.Name}}</span>        <span>{{humanSize .Size}}</span>    </div>    {{end}}</body></html>這是 1.1.1。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 219 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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