Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpolden/echoip.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2018-03-19 21:54:24 +0300
committerMartin Polden <mpolden@mpolden.no>2018-03-19 21:54:24 +0300
commit184676ba297c440a8babbc7e37a3b528711625b8 (patch)
treec644e9b61d1643348754584f933e148cca90f695 /http
parentb01bddb63efbe854745dc96e3b677051dc8dfa02 (diff)
Simplify
Diffstat (limited to 'http')
-rw-r--r--http/http.go15
-rw-r--r--http/http_test.go4
2 files changed, 7 insertions, 12 deletions
diff --git a/http/http.go b/http/http.go
index b7d4eec..c04f514 100644
--- a/http/http.go
+++ b/http/http.go
@@ -13,7 +13,6 @@ import (
"net"
"net/http"
"strconv"
- "strings"
)
const (
@@ -24,7 +23,7 @@ const (
type Server struct {
Template string
IPHeader string
- LookupAddr func(net.IP) ([]string, error)
+ LookupAddr func(net.IP) (string, error)
LookupPort func(net.IP, uint64) error
db database.Client
}
@@ -72,10 +71,9 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
ipDecimal := iputil.ToDecimal(ip)
country, _ := s.db.Country(ip)
city, _ := s.db.City(ip)
- var hostnames []string
+ var hostname string
if s.LookupAddr != nil {
- h, _ := s.LookupAddr(ip)
- hostnames = h
+ hostname, _ = s.LookupAddr(ip)
}
return Response{
IP: ip,
@@ -83,17 +81,14 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
Country: country.Name,
CountryISO: country.ISO,
City: city,
- Hostname: strings.Join(hostnames, " "),
+ Hostname: hostname,
}, nil
}
func (s *Server) newPortResponse(r *http.Request) (PortResponse, error) {
lastElement := filepath.Base(r.URL.Path)
port, err := strconv.ParseUint(lastElement, 10, 16)
- if err != nil {
- return PortResponse{Port: port}, err
- }
- if port < 1 || port > 65355 {
+ if err != nil || port < 1 || port > 65355 {
return PortResponse{Port: port}, fmt.Errorf("invalid port: %d", port)
}
ip, err := ipFromRequest(s.IPHeader, r)
diff --git a/http/http_test.go b/http/http_test.go
index b4a9e05..66a3027 100644
--- a/http/http_test.go
+++ b/http/http_test.go
@@ -11,8 +11,8 @@ import (
"github.com/mpolden/ipd/iputil/database"
)
-func lookupAddr(net.IP) ([]string, error) { return []string{"localhost"}, nil }
-func lookupPort(net.IP, uint64) error { return nil }
+func lookupAddr(net.IP) (string, error) { return "localhost", nil }
+func lookupPort(net.IP, uint64) error { return nil }
type testDb struct{}