-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Description
What version of Go are you using (go version
)?
$ go version go version go1.14.4 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/cheng/.cache/go-build" GOENV="/home/cheng/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/cheng/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build426061178=/tmp/go-build -gno-record-gcc-switches"
What did you do?
http get and parse html, extract their href
// Package util provides ...
package util
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/PuerkitoBio/goquery"
)
func DiscoverVersions(baseUrl string) ([]string, error) {
if !strings.HasSuffix(baseUrl, "/") {
baseUrl = fmt.Sprintf("%s/", baseUrl)
}
res, err := http.Get(baseUrl)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
errMsg := fmt.Sprintf("status code error: %s", res.Status)
return nil, errors.New(errMsg)
}
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
return nil, err
}
var versions []string
doc.Find("ul li a").Each(func(i int, s *goquery.Selection) {
if href, exists := s.Attr("href"); exists {
versions = append(versions, href)
}
})
return versions, nil
}
It gives me error:
2020-09-16T09:47:51.469+0200 ERROR version https://username:password@example.com/software/release/, error: Get " https://username:password@example.com/software/release": dial tcp: lookup example.com: no such host
What did you expect to see?
DNS lookup for http get should work for most of the time
What did you see instead?
DNS lookup fails frequently
xanterx, EtienneBruines, zhitongdaohe and MatthewFagan