moonmq
moonmq copied to clipboard
The way to determine tcp/unix may be not so right.
Take a look at this:
n := "tcp"
if strings.Contains(cfg.Addr, "/") {
n = "unix"
}
When cfg.Addr equals to ./server.sock, everything is ok. But what happen when cfg.Addr is server.sock? Absolutely, something goes wrong.
I notice that, when net.ResolveTCPAddr returns an error, then we can say cfg.Addr is a unix address
n := "tcp"
if _, err := net.ResolveTCPAddr("tcp", cfg.Addr); err != nil {
n = "unix"
}
Thanks!
I see some other apps use above way to select tcp network and don't think it is a big problem because the config address is set by yourself, if you set invalid, dial will be error, you will be responsible for your configuration.
Thanks you!
Yeah, I see. It's really the user's responsibility to do that. Maybe I just want to make everything right as possible as i can. Thank you.