removed error checking from hostname to only return unknown host

Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
Michael 2021-06-30 21:36:25 +01:00
parent 9436e7359b
commit b4aa90c793
2 changed files with 4 additions and 13 deletions

View File

@ -80,9 +80,5 @@ func (logger *Logger) AccessMessage(r *http.Request, statuscode int) {
if err != nil {
logger.Error.Warn(err)
}
hostname, err := nettools.Hostname(ip)
if err != nil {
logger.Error.Warn(err)
}
logger.Access.Infof("%s %v - %s %s %s", ip, hostname, r.Method, colour.Status(statuscode), html.EscapeString(r.URL.Path))
logger.Access.Infof("%s %v - %s %s %s", ip, nettools.Hostname(ip), r.Method, colour.Status(statuscode), html.EscapeString(r.URL.Path))
}

View File

@ -2,7 +2,6 @@ package nettools
import (
"encoding/hex"
"fmt"
"log"
"math/big"
"net"
@ -50,14 +49,10 @@ func Inet6AtonDecode(ipHex string) (ip net.IP) {
}
// Hostname returns hostname
func Hostname(ip net.IP) ([]string, error) {
func Hostname(ip net.IP) (hostname string) {
names, err := net.LookupAddr(ip.String())
unknown := []string{"unknown host"}
if err != nil {
return unknown, err
return "unknown host"
}
if len(names) == 0 {
return unknown, fmt.Errorf("unknown hostname for %v", ip.String())
}
return names, nil
return names[0]
}