updated functions, templates
This commit is contained in:
parent
bbc0b707e8
commit
f77f3f95a9
17
functions.go
17
functions.go
@ -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,25 +24,24 @@ 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)
|
||||
err = ip.GetIPInfo(c)
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "error.html", nil)
|
||||
return c.Render(http.StatusInternalServerError, "error.html", err)
|
||||
}
|
||||
|
||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
||||
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -4,5 +4,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Error</h1>
|
||||
<p>{{ . }} isn't a IP address</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user