Extract head to own template

This commit is contained in:
Jan Bader 2016-12-07 16:42:56 +01:00
parent 1fa6c43df1
commit ed0b939a75
3 changed files with 24 additions and 25 deletions

21
main.go
View File

@ -12,34 +12,31 @@ func main() {
router.LoadHTMLGlob("./templates/*")
router.Static("/static", "./static")
// Middleware
//e.Use(middleware.Logger())
//e.Use(middleware.Recover())
router.GET("/login.html", login)
a := router.Group("/api/v1")
api := router.Group("/api/v1")
{
a.GET("/logout", logout)
a.GET("/login", func(c *gin.Context) {
api.GET("/logout", logout)
api.GET("/login", func(c *gin.Context) {
c.Redirect(http.StatusPermanentRedirect, "/login.html")
})
a.POST("/login", loginPost)
api.POST("/login", loginPost)
// Unauthenticated routes
a.GET("/check", func(c *gin.Context) {
api.GET("/check", func(c *gin.Context) {
c.String(http.StatusOK, "Accessible")
})
a.GET("/hello", func(c *gin.Context) {
api.GET("/hello", func(c *gin.Context) {
c.String(http.StatusOK, "Hello, World!")
})
}
// Restricted group
r := a.Group("/restricted")
r := api.Group("/restricted")
{
//r.Use(middleware.JWT([]byte(secret)))
r.GET("", restricted)
}
}
router.Run(":1323")
}

10
templates/head.html Normal file
View File

@ -0,0 +1,10 @@
{{define "head"}}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="/static/css/bootstrap.min.css" rel="stylesheet" />
<link href="/static/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="/static/css/main.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
{{end}}

View File

@ -3,14 +3,7 @@
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="/static/css/bootstrap.min.css" rel="stylesheet" />
<link href="/static/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="/static/css/main.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
{{template "head"}}
<script>
$(document).ready(function() {
@ -26,7 +19,6 @@
});
</script>
</head>
<head><title>Login</title>
<body>
<div class="container" id="head">
Budgeteer