From 049b7e727fde8c86245060563373f46cb3389dc8 Mon Sep 17 00:00:00 2001 From: George Shammas Date: Tue, 8 Jul 2014 20:15:09 -0400 Subject: [PATCH] Template loaded, @zellio will write splash page. --- main.go | 13 +++++++------ templates/index.html | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 templates/index.html diff --git a/main.go b/main.go index 48cad46..15afaf6 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,13 @@ package main import ( "fmt" "net" + "net/http" "os" + "path" "strings" "time" + "github.com/gin-gonic/gin" - "net/http" - "path" ) func Logger() gin.HandlerFunc { @@ -39,7 +40,6 @@ func Logger() gin.HandlerFunc { } } - func mainHandler(c *gin.Context) { fields := strings.Split(c.Params.ByName("field"), ".") ip, err := net.ResolveTCPAddr("tcp", c.Req.RemoteAddr) @@ -53,7 +53,7 @@ func mainHandler(c *gin.Context) { c.Set("encoding", c.Req.Header.Get("Accept-Encoding")) hostnames, err := net.LookupAddr(ip.IP.String()) - if err != nil { + if err != nil { c.Set("host", "") } else { c.Set("host", hostnames[0]) @@ -71,7 +71,7 @@ func mainHandler(c *gin.Context) { if ua[0] == "curl" { c.String(200, fmt.Sprintln(ip.IP)) } else { - c.String(200, "Page Coming Soon") + c.HTML(200, "index.html", c.Keys) } return case "request": @@ -98,7 +98,7 @@ func FileServer(root string) gin.HandlerFunc { return func(c *gin.Context) { file := c.Params.ByName("file") if !strings.HasPrefix(file, "/") { - file = "/"+file + file = "/" + file } http.ServeFile(c.Writer, c.Req, path.Join(root, path.Clean(file))) } @@ -108,6 +108,7 @@ func main() { r := gin.New() r.Use(gin.Recovery()) r.Use(Logger()) + r.LoadHTMLTemplates("templates/*") r.GET("/:field", mainHandler) r.GET("/", mainHandler) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d1e6a5e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ + + + + + IFCONFIG.IO + + +{{ .ip }} + + \ No newline at end of file