Skip to content

Commit

Permalink
add serving HTML static & dynamic pages with 404 and landing pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Massad committed Jan 10, 2017
1 parent f19c5fa commit b53f3d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"fmt"
"net/http"
"runtime"

"github.com/Massad/gin-boilerplate/controllers"
"github.com/Massad/gin-boilerplate/db"
Expand Down Expand Up @@ -58,7 +60,20 @@ func main() {
v1.DELETE("/article/:id", article.Delete)
}

r.LoadHTMLGlob("./public/html/*")

r.Static("/public", "./public")

r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{
"ginBoilerplateVersion": "v0.02",
"goVersion": runtime.Version(),
})
})

r.NoRoute(func(c *gin.Context) {
c.HTML(404, "404.html", gin.H{})
})

r.Run(":9000")
}
14 changes: 14 additions & 0 deletions public/html/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>

<head>
<title>404 Page</title>
</head>

<body>
<br /> <br /><br />
<center>
<h3>Opss!! 404 again?</h3>
</center>
</body>

</html>
14 changes: 14 additions & 0 deletions public/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>

<head>
<title>Gin Boilerplate</title>
</head>

<body>
<br /> <br /><br />
<center>
<h3>Welcome to Golang {{ .goVersion}} with <a href="https://github.com/Massad/gin-boilerplate" target="_blank" title="Gin Boilerplate">Gin Boilerplate</a> version: {{ .ginBoilerplateVersion}}</h3>
</center>
</body>

</html>

0 comments on commit b53f3d8

Please sign in to comment.