fix: override DNS resolver for CGO_ENABLED=0 Android builds
The pure-Go DNS resolver falls back to [::1]:53 on Android because /etc/resolv.conf does not exist, causing all hostname-based API calls to fail. Use 8.8.8.8:53 via net.DefaultResolver.Dial as fallback. When CGO is enabled (Termux), the cgo resolver is used and this override is never called. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3b3c3bc884
commit
c0babbc643
1 changed files with 11 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
|
|
@ -114,6 +115,16 @@ func copyDirectory(src, dst string) error {
|
|||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Override DNS resolver for CGO_ENABLED=0 builds (Android APK).
|
||||
// The pure-Go resolver falls back to [::1]:53 on Android because
|
||||
// /etc/resolv.conf does not exist. When CGO is enabled (Termux),
|
||||
// the cgo resolver is used instead and this Dial is never called.
|
||||
net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return (&net.Dialer{}).DialContext(ctx, "udp", "8.8.8.8:53")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
printHelp()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue