I created a solution that works for me. Two functions that do the conversion between net.IP and int64 (I'm using int64 as mongodb does not support uint). The reason that I'm using an integer is that it can easily be used to link a certain ip address with an iprange.
But of course It would be better to have a standard solution in the net package that does also work for IPv6.
// Convert uint to net.IP
func inet_ntoa(ipnr int64) net.IP {
var bytes [4]byte
bytes[0] = byte(ipnr & 0xFF)
bytes[1] = byte((ipnr >> 8) & 0xFF)
bytes[2] = byte((ipnr >> 16) & 0xFF)
bytes[3] = byte((ipnr >> 24) & 0xFF)
return net.IPv4(bytes[3],bytes[2],bytes[1],bytes[0])
}
// Convert net.IP to int64
func inet_aton(ipnr net.IP) int64 {
bits := strings.Split(ipnr.String(), ".")
b0, _ := strconv.Atoi(bits[0])
b1, _ := strconv.Atoi(bits[1])
b2, _ := strconv.Atoi(bits[2])
b3, _ := strconv.Atoi(bits[3])
var sum int64
sum += int64(b0) << 24
sum += int64(b1) << 16
sum += int64(b2) << 8
sum += int64(b3)
return sum