本文整理匯總了Golang中github.com/gin-gonic/gin.Engine.HTMLRender方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.HTMLRender方法的具體用法?Golang Engine.HTMLRender怎麽用?Golang Engine.HTMLRender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Engine
的用法示例。
在下文中一共展示了Engine.HTMLRender方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InitAssetsTemplates
// InitAssetsTemplates initializes the router to use either a ricebox or the
// filesystem in case the ricebox couldn't be found.
func InitAssetsTemplates(r *gin.Engine, tbox, abox *rice.Box, verbose bool, names ...string) error {
var err error
if tbox != nil {
mt := multitemplate.New()
var tmpl string
var message *template.Template
for _, x := range names {
if tmpl, err = tbox.String(x); err != nil {
return err
}
if message, err = template.New(x).Parse(tmpl); err != nil {
return err
}
mt.Add(x, message)
}
logger.Debug("server", "Loaded templates from \"templates\" box")
r.HTMLRender = mt
} else {
r.LoadHTMLGlob("templates/*")
logger.Debug("server", "Loaded templates from disk")
}
if abox != nil {
r.StaticFS("/static", abox.HTTPBox())
logger.Debug("server", "Loaded assets from \"assets\" box")
} else {
r.Static("/static", "assets")
logger.Debug("server", "Loaded assets from disk")
}
return nil
}
示例2: LoadTemplates
func LoadTemplates(engine *gin.Engine, path string) {
err := BuildTemplate(path)
if err != nil {
fmt.Println(err)
}
engine.HTMLRender = HTMLNi{
tplPath: path,
}
}
示例3: ExposeRoutes
func ExposeRoutes(router *gin.Engine) {
router.LoadHTMLGlob("web/templates/*.html")
router.HTMLRender = createCustomRender()
if config.IsEnvironment("production") && config.GetConfig("SPACE_CDN") != "" {
spaceCDN = config.GetConfig("SPACE_CDN")
} else {
spaceCDN = "/public"
router.Static("/public", "web/public")
}
store := sessions.NewCookieStore([]byte(config.GetConfig("SPACE_SESSION_SECRET")))
store.Options(sessions.Options{
Secure: config.IsEnvironment("production"),
HttpOnly: true,
})
router.Use(sessions.Sessions("jupiter.session", store))
views := router.Group("/")
{
views.GET("/", jupiterHandler)
views.GET("/profile", jupiterHandler)
views.GET("/signup", func(c *gin.Context) {
c.HTML(http.StatusOK, "satellite", utils.H{
"AssetsEndpoint": spaceCDN,
"Title": " - Sign up",
"Satellite": "io",
"Data": utils.H{
"feature.gates": utils.H{
"user.create": feature.Active("user.create"),
},
},
})
})
views.GET("/signin", func(c *gin.Context) {
c.HTML(http.StatusOK, "satellite", utils.H{
"AssetsEndpoint": spaceCDN,
"Title": " - Sign in",
"Satellite": "ganymede",
})
})
views.GET("/signout", func(c *gin.Context) {
session := sessions.Default(c)
userPublicId := session.Get("userPublicId")
if userPublicId != nil {
session.Delete("userPublicId")
session.Save()
}
c.Redirect(http.StatusFound, "/signin")
})
views.GET("/session", func(c *gin.Context) {
session := sessions.Default(c)
userPublicId := session.Get("userPublicId")
if userPublicId != nil {
c.Redirect(http.StatusFound, "/")
return
}
var nextPath string = "/"
var scope string = c.Query("scope")
var grantType string = c.Query("grant_type")
var code string = c.Query("code")
var clientId string = c.Query("client_id")
var _nextPath string = c.Query("_")
//var state string = c.Query("state")
if scope == "" || grantType == "" || code == "" || clientId == "" {
// Original response:
// c.String(http.StatusMethodNotAllowed, "Missing required parameters")
c.Redirect(http.StatusFound, "/signin")
return
}
if _nextPath != "" {
if _nextPath, err := url.QueryUnescape(_nextPath); err == nil {
nextPath = _nextPath
}
}
client := services.FindOrCreateClient("Jupiter")
if client.Key == clientId && grantType == oauth.AuthorizationCode && scope == models.PublicScope {
grantToken := services.FindSessionByToken(code, models.GrantToken)
if grantToken.ID != 0 {
session.Set("userPublicId", grantToken.User.PublicId)
session.Save()
services.InvalidateSession(grantToken)
c.Redirect(http.StatusFound, nextPath)
return
}
}
c.Redirect(http.StatusFound, "/signin")
})
views.GET("/authorize", authorizeHandler)
views.POST("/authorize", authorizeHandler)
//.........這裏部分代碼省略.........