From f595597fc07bd41bb54bb62a49311dcb404c0d24 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 21 Jan 2020 18:42:34 +0100 Subject: [PATCH] updated dip --- functions.go | 15 ++++++--------- templates/admin.html | 0 templates/error.html | 4 ++-- templates/head.html | 11 ++++++----- templates/index.html | 1 - 5 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 templates/admin.html diff --git a/functions.go b/functions.go index a8bb775..9c70cb7 100644 --- a/functions.go +++ b/functions.go @@ -2,12 +2,12 @@ package main import ( "flag" - "fmt" + "fmt" + "log" "net" "net/http" "os" "strings" - "log" "github.com/labstack/echo/v4" "github.com/likexian/whois-go" @@ -24,12 +24,12 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) { err = ip.CheckIPAddress() if err != nil { - return err + return err } err = ip.GetHostname() if err != nil { - log.Println(err) + log.Println(err) } return @@ -39,10 +39,7 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) { func Dip(c echo.Context) (err error) { var ip IP - err = ip.GetIPInfo(c) - if err != nil { - return c.Render(http.StatusInternalServerError, "error.html", err) - } + ip.GetIPInfo(c) if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) { return c.Render(http.StatusOK, "index.html", ip) @@ -70,7 +67,7 @@ func (ip *IP) CheckIPAddress() (err error) { func (ip *IP) GetHostname() (err error) { revip, err := net.LookupAddr(ip.IP) if err != nil { - return fmt.Errorf(fmt.Sprintf("Supplied address \"%s\" doesn't have a valid reverse DNS entry", ip.IP)) + return err } ip.Hostname = revip[0] return diff --git a/templates/admin.html b/templates/admin.html deleted file mode 100644 index e69de29..0000000 diff --git a/templates/error.html b/templates/error.html index d4839dd..9f8f4a1 100644 --- a/templates/error.html +++ b/templates/error.html @@ -1,9 +1,9 @@ - Public IP Address + {{ template "head.html" .}}

Error

-

{{ . }} isn't a IP address

+

{{ . }}

diff --git a/templates/head.html b/templates/head.html index 564f7c1..3b14e77 100644 --- a/templates/head.html +++ b/templates/head.html @@ -1,5 +1,6 @@ - - - - - \ No newline at end of file + Public IP Address + + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index b27e7e5..0c6b757 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,5 @@ - Public IP Address {{ template "head.html" .}}