Template loaded, @zellio will write splash page.

This commit is contained in:
George Shammas 2014-07-08 20:15:09 -04:00
parent 1e55bc33b1
commit 049b7e727f
2 changed files with 17 additions and 6 deletions

View File

@ -3,12 +3,13 @@ package main
import ( import (
"fmt" "fmt"
"net" "net"
"net/http"
"os" "os"
"path"
"strings" "strings"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"path"
) )
func Logger() gin.HandlerFunc { func Logger() gin.HandlerFunc {
@ -39,7 +40,6 @@ func Logger() gin.HandlerFunc {
} }
} }
func mainHandler(c *gin.Context) { func mainHandler(c *gin.Context) {
fields := strings.Split(c.Params.ByName("field"), ".") fields := strings.Split(c.Params.ByName("field"), ".")
ip, err := net.ResolveTCPAddr("tcp", c.Req.RemoteAddr) ip, err := net.ResolveTCPAddr("tcp", c.Req.RemoteAddr)
@ -71,7 +71,7 @@ func mainHandler(c *gin.Context) {
if ua[0] == "curl" { if ua[0] == "curl" {
c.String(200, fmt.Sprintln(ip.IP)) c.String(200, fmt.Sprintln(ip.IP))
} else { } else {
c.String(200, "Page Coming Soon") c.HTML(200, "index.html", c.Keys)
} }
return return
case "request": case "request":
@ -108,6 +108,7 @@ func main() {
r := gin.New() r := gin.New()
r.Use(gin.Recovery()) r.Use(gin.Recovery())
r.Use(Logger()) r.Use(Logger())
r.LoadHTMLTemplates("templates/*")
r.GET("/:field", mainHandler) r.GET("/:field", mainHandler)
r.GET("/", mainHandler) r.GET("/", mainHandler)

10
templates/index.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>IFCONFIG.IO</title>
</head>
<body>
{{ .ip }}
</body>
</html>