> on input "localhost", it returns {"127.0.0.1","::1"},
> but on inputs "127.0.0.1" or "::1" it returns a DNS error.
>
> One would expect that all three inputs return the same result.
>
> Since the user enters their allowed hosts as a string,
> the program should expect any of "127.0.0.1", "localhost" or "::1",
> but LookupHost behaves differently on them.
LookupHost is for looking up host names.
Other people might expect that looking up 127.0.0.1
should return "localhost" (the same way that
"host 18.26.4.9" behaves on the command line).
It sounds like the thing to do is pass the string specified
by the user ("localhost" or "127.0.0.1") to ParseIP.
If you get nil back, then try to resolve it as a host name
and add all the IP addresses you get back.
When you get the RemoteAddr() from the connection,
instead of calling String(), do an interface check to see
if it is a *net.TCPAddr (it will be). Then pull out the IP
field from that struct and compare against the list.
It appears that there is no IP comparison function in
package net. I'll add one later, but for now you can use
func EqualIP(x, y net.IP) bool {
return bytes.Equal(x.To16(), y.To16())
}
Russ