diff --git a/functions.go b/functions.go index cd1557f..a8bb775 100644 --- a/functions.go +++ b/functions.go @@ -2,7 +2,7 @@ package main import ( "flag" - "fmt" + "fmt" "net" "net/http" "os" @@ -15,7 +15,7 @@ import ( ) // GetIPInfo returns IP address informations -func GetIPInfo(c echo.Context) (ip IP, err error) { +func (ip *IP) GetIPInfo(c echo.Context) (err error) { if c.QueryParam("ip") != "" { ip.IP = c.QueryParam("ip") } else { @@ -24,26 +24,25 @@ func GetIPInfo(c echo.Context) (ip IP, err error) { err = ip.CheckIPAddress() if err != nil { - log.Println(fmt.Sprintf("Error checking IP address %s",ip.IP)) + return err } err = ip.GetHostname() if err != nil { - log.Println(fmt.Sprintf("Error checking revers DNS for IP address %s",ip.IP)) + log.Println(err) } return } -// Dip return webpage +// Dip returns webpage func Dip(c echo.Context) (err error) { var ip IP - ip, err = GetIPInfo(c) - fmt.Println(err) - if err != nil { - return c.Render(http.StatusInternalServerError, "error.html", nil) - } + err = ip.GetIPInfo(c) + if err != nil { + return c.Render(http.StatusInternalServerError, "error.html", err) + } if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) { return c.Render(http.StatusOK, "index.html", ip) @@ -62,7 +61,7 @@ func Static(c echo.Context) (err error) { func (ip *IP) CheckIPAddress() (err error) { addr := net.ParseIP(ip.IP) if addr == nil { - return fmt.Errorf("Supplied string isn't an IP address") + return fmt.Errorf("Supplied string isn't an IP address \"%s\"", ip.IP) } return } @@ -71,7 +70,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 fmt.Errorf(fmt.Sprintf("Supplied address \"%s\" doesn't have a valid reverse DNS entry", ip.IP)) } ip.Hostname = revip[0] return diff --git a/templates.go b/templates.go index da8c2fd..535bd97 100644 --- a/templates.go +++ b/templates.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "html/template" "io" "strings" @@ -32,7 +31,6 @@ func BuildTemplates(box packr.Box) (builttemplates *Template, err error) { tmpl := template.New("template") for _, filename := range box.List() { - fmt.Println(filename) tmplContent, _ := box.FindString(filename) tmpl.New(filename).Parse(tmplContent) } diff --git a/templates/error.html b/templates/error.html index 684a0b2..d4839dd 100644 --- a/templates/error.html +++ b/templates/error.html @@ -4,5 +4,6 @@

Error

+

{{ . }} isn't a IP address

- \ No newline at end of file + diff --git a/templates/index.html b/templates/index.html index 50c381a..b27e7e5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,7 +4,7 @@ {{ template "head.html" .}} -

IP: {{ .IP }}

-

Reverse DNS: {{ .Hostname }}

+

IP : {{ .IP }}

+

Reverse DNS : {{ .Hostname }}

- \ No newline at end of file +