有没有一种方法可以强制刷新主机?

I am running a Beego application that relies on updates in /etc/hosts (via Docker links) to find other servers. /etc/hosts updates fine but the application will not use new hosts unless it is either restarted or after it has waited way too long. After reviewing the documentation for src/net/hosts it looks like I am locked into a 5 minute refresh time.

Is there a way to force this cache to refresh or am I looking at this problem the wrong way?

The hosts file cache time in Go was shortened to 5 seconds. The behaviour of Go differs whether the pure Go (default, with exceptions) or Cgo resolver is used. To avoid the Go internal cache of the pure Go resolver there is currently no way other than to force the Cgo resolver.

There are various ways to force Go to use the Cgo resolver. The way to force Go to use the Cgo resolver suggested by the documentation is to set the environment variable GODEBUG to netdns=cgo.