亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

Go 模板 - 從對象存儲/數據庫加載

Go 模板 - 從對象存儲/數據庫加載

Go
慕碼人8056858 2021-10-18 14:16:11
我正在重建一個支持客戶特定模板(主題)的應用程序,從 node.js 到 Go。我目前正在使用渲染來渲染我的模板文件,但我實際上需要做的是訪問存儲在對象存儲(如 Cloudfiles)中的模板。在 node.js 中,我使用 express 完成了此操作,并且正在覆蓋該render()方法,但我無法弄清楚如何在 Go 中執行此操作。我基本上需要做這樣的事情:func (c *Controller) MyRouteHandler (rw http.ResponseWriter, req *http.Request) {    // retrieve the store from the context (assigned in middleware chain)    store := context.Get(req, "store").(*Store)     ... do some stuff like load the entity from the database    // retrieve the template from the Object store and     // create the template instance (template.New("template").Parse(...))    tpl := c.ObjectStore.LoadTemplate(store, entity.TemplateFile)    // I know render's .HTML function takes the path to the template     // so I'll probably need to show the html a different way    c.HTML(rw, http.StatusOK, tpl, &PageContext{Title: "My Page", Entity: &entity})}如果需要,我可以通過執行以下操作來動態包含子模板:http : //play.golang.org/p/7BCPHdKRi2但老實說,這似乎不是一個好方法。我一直在尋找解決方案,但一直遇到障礙。任何建議/幫助都會很棒。編輯:本質上,我要問以下問題:如何基于每個請求從數據存儲加載特定模板。然后我如何將其作為對客戶端的響應發送
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號