我正在重建一個支持客戶特定模板(主題)的應用程序,從 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但老實說,這似乎不是一個好方法。我一直在尋找解決方案,但一直遇到障礙。任何建議/幫助都會很棒。編輯:本質上,我要問以下問題:如何基于每個請求從數據存儲加載特定模板。然后我如何將其作為對客戶端的響應發送
Go 模板 - 從對象存儲/數據庫加載
慕碼人8056858
2021-10-18 14:16:11