mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: add mechanisms to force go or cgo lookup, and to debug default strategy
GODEBUG=netdns=1 prints a one-time strategy decision. (cgo or go DNS lookups) GODEBUG=netdns=2 prints the per-lookup strategy as a function of the hostname. The new "netcgo" build tag forces cgo DNS lookups. GODEBUG=netdns=go (or existing build tag "netgo") forces Go DNS resolution. GODEBUG=netdns=cgo (or new build tag "netcgo") forces libc DNS resolution. Options can be combined with e.g. GODEBUG=netdns=go+1 or GODEBUG=netdns=2+cgo. Fixes #11322 Fixes #11450 Change-Id: I7a67e9f759fd0a02320e7803f9ded1638b19e861 Reviewed-on: https://go-review.googlesource.com/11584 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
4c332508f9
commit
b615ad8fd5
7 changed files with 153 additions and 3 deletions
|
|
@ -361,3 +361,26 @@ func readFull(r io.Reader) (all []byte, err error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// goDebugString returns the value of the named GODEBUG key.
|
||||
// GODEBUG is of the form "key=val,key2=val2"
|
||||
func goDebugString(key string) string {
|
||||
s := os.Getenv("GODEBUG")
|
||||
for i := 0; i < len(s)-len(key)-1; i++ {
|
||||
if i > 0 && s[i-1] != ',' {
|
||||
continue
|
||||
}
|
||||
afterKey := s[i+len(key):]
|
||||
if afterKey[0] != '=' || s[i:i+len(key)] != key {
|
||||
continue
|
||||
}
|
||||
val := afterKey[1:]
|
||||
for i, b := range val {
|
||||
if b == ',' {
|
||||
return val[:i]
|
||||
}
|
||||
}
|
||||
return val
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue