ADDED: * The ability to show both IPv4 and IPv6 addresses (if the client has dual-stack and either the server does as well or a separate ClientInfo is running on the "other" net family).
55 lines
763 B
Go
55 lines
763 B
Go
package server
|
|
|
|
import (
|
|
`fmt`
|
|
)
|
|
|
|
func (p *Page) AltURL() (altUrl string) {
|
|
|
|
if !p.HasAltURL() {
|
|
return
|
|
}
|
|
|
|
if p.Info.IP.Is4() {
|
|
altUrl = p.srv.v6Url.String()
|
|
} else if p.Info.IP.Is6() {
|
|
altUrl = p.srv.v4Url.String()
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (p *Page) AltVer() (altVer string) {
|
|
|
|
if !p.HasAltURL() {
|
|
return
|
|
}
|
|
|
|
if p.Info.IP.Is4() {
|
|
altVer = "v6"
|
|
} else if p.Info.IP.Is6() {
|
|
altVer = "v4"
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (p *Page) HasAltURL() (hasAlt bool) {
|
|
|
|
if p.Info == nil {
|
|
return
|
|
}
|
|
|
|
hasAlt = (p.Info.IP.Is4() && p.srv.v6Url != nil) ||
|
|
(p.Info.IP.Is6() && p.srv.v4Url != nil)
|
|
|
|
return
|
|
}
|
|
|
|
func (p *Page) RenderIP(indent uint) (s string) {
|
|
|
|
s = fmt.Sprintf("<a href=\"https://ipinfo.io/%s\">%s</a>", p.Info.IP.String(), p.Info.IP.String())
|
|
|
|
return
|
|
}
|