How can I check the nil value as a result of the assignment of variable b below?
package main
import (
"fmt"
"net"
)
type Subnet struct {
ID int
IP *net.IPNet
}
func main() {
var s = Subnet{
ID: 12345,
IP: &net.IPNet{
IP: net.IP{10, 1, 232, 0},
Mask: net.IPMask{255, 255, 255, 0},
},
}
fmt.Printf("%+v
", s)
var b = Subnet{
ID: 12345,
IP: &net.IPNet{},
}
fmt.Printf("%+v
", b)
if b.IP == nil {
fmt.Println("hello there")
}
}
Here is the go playground https://play.golang.org/p/Jk6_3ofyH5
Basically, I expect that "hello there" will be printed out as b.IP is nil, but it did not.