尝试 DNS 解析时遇到拨号错误
I have already put the name "gracefulrpc" in the /etc/hosts: cat /etc/hosts 127.0.0.1 localhost gracefulrpc 127.0.1.1 bluven But the dial error still occurs. I also tested with the name "dns:///localhost:3456" which worked: ➜ api git:(main) ✗ go run . dns:///localhost:3456 # the result of c.BuildTarget()
{"@timestamp":"2025-09-19T15:27:07.092+08:00","caller":"p2c/p2c.go:181","content":"p2c - conn: 127.0.0.1:3456, load: 5602, reqs: 1","level":"stat"} 15:27:07 from host: bluven {"@timestamp":"2025-09-19T15:27:07.093+08:00","caller":"handler/loghandler.go:147","content":"[HTTP] 200 - GET /api/graceful - 127.0.0.1:45866 - curl/8.5.0","duration":"31.6ms","level":"info","span":"334b0c588f993a32","trace":"c0933427d05b176ba5177f08c9cc3c41"} I also tested gracefulrpc:3456 with the nc command: api git:(main) ✗ nc -zv gracefulrpc 3456 Connection to gracefulrpc (127.0.0.1) 3456 port [tcp/*] succeeded! The api config is: { "Name": "graceful-api", "Host": "0.0.0.0", "Port": 8888, "MaxConns": 1000000, "Rpc": { "Target": "dns:///localhost:3456" } } In the original config, the Target field is named Server which is wrong, so I changed it. So, how should I do to make the example run successfully?
内容来源: zeromicro/go-zero