(host string)
| 87 | } |
| 88 | |
| 89 | func dnsResolve(host string) (res netip.Addr) { |
| 90 | ctx, cl := context.WithTimeout(context.Background(), 5*time.Second) |
| 91 | defer cl() |
| 92 | // lookup "ip" network for better cache coherence with other lookups, |
| 93 | // even though we actually interested only in IPv4 only |
| 94 | addrs, err := DefaultResolver.LookupNetIP(ctx, "ip", host) |
| 95 | if err != nil { |
| 96 | return |
| 97 | } |
| 98 | for _, ip := range addrs { |
| 99 | ip = ip.Unmap() |
| 100 | if ip.Is4() { |
| 101 | return ip |
| 102 | } |
| 103 | } |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | func AddDNSResolve(vm *goja.Runtime) error { |
| 108 | return vm.GlobalObject().Set("dnsResolve", func(call goja.FunctionCall) goja.Value { |
no test coverage detected