本文整理匯總了Golang中github.com/hypertornado/prago.App.LoadTemplateFromString方法的典型用法代碼示例。如果您正苦於以下問題:Golang App.LoadTemplateFromString方法的具體用法?Golang App.LoadTemplateFromString怎麽用?Golang App.LoadTemplateFromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hypertornado/prago.App
的用法示例。
在下文中一共展示了App.LoadTemplateFromString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Init
//Init admin middleware
func (a *Admin) Init(app *prago.App) error {
a.App = app
a.db = app.Data()["db"].(*sql.DB)
a.AdminAccessController = app.MainController().SubController()
a.AdminController = a.AdminAccessController.SubController()
googleApiKey := app.Config.GetStringWithFallback("google", "")
a.AdminController.AddBeforeAction(func(request prago.Request) {
request.SetData("google", googleApiKey)
})
bindDBBackupCron(app)
bindMarkdownAPI(a)
bindListResourceAPI(a)
var err error
a.sendgridClient = sendgrid.NewSendGridClientWithApiKey(app.Config.GetStringWithFallback("sendgridApi", ""))
a.noReplyEmail = app.Config.GetStringWithFallback("noReplyEmail", "")
err = a.bindAdminCommand(app)
if err != nil {
return err
}
err = a.initTemplates(app)
if err != nil {
return err
}
err = app.LoadTemplateFromString(adminTemplates)
if err != nil {
panic(err)
}
a.AdminController.AddAroundAction(func(request prago.Request, next func()) {
request.SetData("admin_yield", "admin_home")
session := request.GetData("session").(*sessions.Session)
userID, ok := session.Values["user_id"].(int64)
if !ok {
prago.Redirect(request, a.Prefix+"/user/login")
return
}
var user User
err := a.Query().WhereIs("id", userID).Get(&user)
if err != nil {
prago.Redirect(request, a.Prefix+"/user/login")
return
}
randomness := app.Config.GetString("random")
request.SetData("_csrfToken", user.CSRFToken(randomness))
request.SetData("currentuser", &user)
request.SetData("locale", GetLocale(request))
request.SetData("appName", a.AppName)
request.SetData("appCode", request.App().Data()["appName"].(string))
request.SetData("appVersion", request.App().Data()["version"].(string))
request.SetData("admin_header", a.adminHeaderData(request))
next()
})
a.AdminController.Get(a.Prefix, func(request prago.Request) {
prago.Render(request, 200, "admin_layout")
})
a.AdminController.Get(a.Prefix+"/_stats", stats)
a.AdminController.Get(a.Prefix+"/_static/admin.js", func(request prago.Request) {
request.Response().Header().Set("Content-type", "text/javascript")
request.Response().WriteHeader(200)
request.Response().Write([]byte(adminJS))
request.SetProcessed()
})
a.App.MainController().Get(a.Prefix+"/_static/admin.css", func(request prago.Request) {
request.Response().Header().Set("Content-type", "text/css; charset=utf-8")
request.Response().WriteHeader(200)
request.Response().Write([]byte(adminCSS))
request.SetProcessed()
})
for i := range a.Resources {
resource := a.Resources[i]
err = a.initResource(resource)
if err != nil {
return err
}
}
a.AdminController.Get(a.Prefix+"/*", func(request prago.Request) {
render404(request)
})
//.........這裏部分代碼省略.........