I believe the title is pretty self explanatory, but just in case, I'll explain further.
I am writing a function in Go that uses icmp to check if a particular service is running. I got this idea from ping implemented in Go. When I try command line ping, it can not resolve 127.0.0.1:8080
, and the function follows suit, which makes sense. But can I use icmp to check that address and port with something I missing? Or should I just stick something like tcp to target a port?
Right now I have this simple function, and I could just use tcp, but I'm curious if I could use something like icmp.
func (c *Controller) Ping() error {
conn, connErr := net.Dial("ip4:icmp", c.APIServerIP)
if connErr != nil {
return connErr
}
conn.SetDeadline(time.Now().Add(3 * time.Second))
defer conn.Close()
return nil
}