mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-02 15:59:04 +02:00
33 lines
730 B
Go
33 lines
730 B
Go
package iplocation
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
|
)
|
|
|
|
type Resolver interface {
|
|
GetLocationByIP(ctx context.Context, ipAddress string) (country string, city string, err error)
|
|
}
|
|
|
|
// LocalLocation returns the labels shared by all providers for non-public addresses
|
|
func LocalLocation(ip net.IP) (country string, city string) {
|
|
if ip == nil {
|
|
return "", ""
|
|
}
|
|
|
|
switch {
|
|
case utils.IsLocalIPv6(ip):
|
|
return "Internal Network", "LAN"
|
|
case utils.IsTailscaleIP(ip):
|
|
return "Internal Network", "Tailscale"
|
|
case utils.IsPrivateIP(ip):
|
|
return "Internal Network", "LAN"
|
|
case utils.IsLocalhostIP(ip):
|
|
return "Internal Network", "localhost"
|
|
default:
|
|
return "", ""
|
|
}
|
|
}
|