godebug does not work with code that imports net/http (since go 1.6)
athirn opened this issue ยท 10 comments
whenever I import net/http
, I get all sorts of errors when I try and run godebug
. The same code works fine when I build and run it with go directly.
Here is a simple example app and the output of go debug....
$cat main.go
package main
import (
"net/http"
)
func HandleIndex(w http.ResponseWriter, r *http.Request) {
// io.WriteString(w, "hello, world\n")
}
func main() {
_ = "breakpoint"
http.HandleFunc("/", HandleIndex)
}
$godebug run main.go
/usr/local/go/src/net/interface_bsd.go:12:2: could not import golang_org/x/net/route (cannot find package "golang_org/x/net/route" in any of:
/usr/local/go/src/golang_org/x/net/route (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/route (from $GOPATH))
/usr/local/go/src/net/interface_darwin.go:10:2: could not import golang_org/x/net/route (cannot find package "golang_org/x/net/route" in any of:
/usr/local/go/src/golang_org/x/net/route (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/route (from $GOPATH))
/usr/local/go/src/net/interface_darwin.go:13:40: undeclared name: route
/usr/local/go/src/net/interface_darwin.go:14:14: undeclared name: route
/usr/local/go/src/net/interface_darwin.go:18:9: undeclared name: route
/usr/local/go/src/net/interface_darwin.go:24:14: undeclared name: route
/usr/local/go/src/net/interface_darwin.go:28:15: undeclared name: route
/usr/local/go/src/net/http/h2_bundle.go:45:2: could not import golang_org/x/net/http2/hpack (cannot find package "golang_org/x/net/http2/hpack" in any of:
/usr/local/go/src/golang_org/x/net/http2/hpack (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/http2/hpack (from $GOPATH))
/usr/local/go/src/net/http/h2_bundle.go:46:2: could not import golang_org/x/net/lex/httplex (cannot find package "golang_org/x/net/lex/httplex" in any of:
/usr/local/go/src/golang_org/x/net/lex/httplex (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/lex/httplex (from $GOPATH))
/usr/local/go/src/net/http/http.go:10:2: could not import golang_org/x/net/lex/httplex (cannot find package "golang_org/x/net/lex/httplex" in any of:
/usr/local/go/src/golang_org/x/net/lex/httplex (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/lex/httplex (from $GOPATH))
/usr/local/go/src/net/http/server.go:31:2: could not import golang_org/x/net/lex/httplex (cannot find package "golang_org/x/net/lex/httplex" in any of:
/usr/local/go/src/golang_org/x/net/lex/httplex (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/lex/httplex (from $GOPATH))
/usr/local/go/src/net/http/transfer.go:21:2: could not import golang_org/x/net/lex/httplex (cannot find package "golang_org/x/net/lex/httplex" in any of:
/usr/local/go/src/golang_org/x/net/lex/httplex (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/lex/httplex (from $GOPATH))
/usr/local/go/src/net/http/transport.go:30:2: could not import golang_org/x/net/lex/httplex (cannot find package "golang_org/x/net/lex/httplex" in any of:
/usr/local/go/src/golang_org/x/net/lex/httplex (from $GOROOT)
/Users/anuaimi/code/go/src/golang_org/x/net/lex/httplex (from $GOPATH))
/usr/local/go/src/net/http/h2_bundle.go:848:19: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:1827:11: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:1851:52: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:1862:51: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:5020:11: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:6735:20: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:3131:18: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:3187:46: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:6834:22: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:6926:30: undeclared name: hpack
/usr/local/go/src/net/http/transport.go:323:8: undeclared name: httplex
/usr/local/go/src/net/http/transport.go:327:9: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:5287:26: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:5290:12: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:6659:4: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:1920:2: invalid operation: hdec (variable of type *invalid type) has no field or method SetEmitEnabled
/usr/local/go/src/net/http/h2_bundle.go:1921:2: invalid operation: hdec (variable of type *invalid type) has no field or method SetMaxStringLength
/usr/local/go/src/net/http/h2_bundle.go:1922:2: invalid operation: hdec (variable of type *invalid type) has no field or method SetEmitFunc
/usr/local/go/src/net/http/h2_bundle.go:1922:27: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:1926:7: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:1942:4: invalid operation: hdec (variable of type *invalid type) has no field or method SetEmitEnabled
/usr/local/go/src/net/http/h2_bundle.go:1948:4: invalid operation: hdec (variable of type *invalid type) has no field or method SetEmitEnabled
/usr/local/go/src/net/http/h2_bundle.go:1957:8: invalid operation: hdec (variable of type *invalid type) has no field or method SetEmitFunc
/usr/local/go/src/net/http/h2_bundle.go:1957:33: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:1962:16: invalid operation: hdec (variable of type *invalid type) has no field or method Write
/usr/local/go/src/net/http/h2_bundle.go:1979:12: invalid operation: hdec (variable of type *invalid type) has no field or method Close
/usr/local/go/src/net/http/h2_bundle.go:5797:7: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:5801:8: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:5892:2: invalid operation: cc.henc (variable of type *invalid type) has no field or method WriteField
/usr/local/go/src/net/http/h2_bundle.go:5892:21: undeclared name: hpack
/usr/local/go/src/net/http/server.go:789:25: undeclared name: httplex
/usr/local/go/src/net/http/server.go:793:7: undeclared name: httplex
/usr/local/go/src/net/http/server.go:797:8: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:2517:7: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:3042:20: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:3045:23: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:3899:3: invalid operation: sc.hpackEncoder (variable of type *invalid type) has no field or method SetMaxDynamicTableSize
/usr/local/go/src/net/http/h2_bundle.go:6711:22: undeclared name: httplex
/usr/local/go/src/net/http/h2_bundle.go:6838:2: invalid operation: enc (variable of type *invalid type) has no field or method WriteField
/usr/local/go/src/net/http/h2_bundle.go:6838:17: undeclared name: hpack
/usr/local/go/src/net/http/h2_bundle.go:6942:8: undeclared name: httplex
/usr/local/go/src/net/http/http.go:42:10: undeclared name: httplex
/usr/local/go/src/net/http/transfer.go:566:14: undeclared name: httplex
/usr/local/go/src/net/http/transfer.go:568:23: undeclared name: httplex
couldn't load packages due to errors: net/http, net
I have some more information. for some reason the file /usr/local/go//src/net/http/h2_bundle.go has an include for golang_org/x/net/http2/hpack
. Not sure why is golang_org rather golang.org.
I believe it has something to do with this bug golang/go#16333.
Still don't understand why building the code normally works but it fails with godebug
OK, I found where the golang_org directory is. It's vendor in go 1.7 (/usr/local/go/src/vendor/golang_org/).
So the issues is that when I use godebug, it's not supporting the vendoring directory. If you look at the top of the original error, you can see its checking 3 directories for the golang_org/x/route package. But the list does not contain the vendor subdir
@athirn sorry
I still don't know how to fix this
My problem is the same as yours.
Could you show me how you fix this?
@athirn thank you.
I found a way to fix this.
cp -R golang_org $GOPATH/src
Thanks go2run for the above comment
For those who are new to this like me, cp -R copies all files in golang_or.
what I did was
cd $GOPATH/src
then
cp -R /usr/local/go/src/vendor/golang_org .
I just symlinked em for now
ln -s golang.org golang_org
For those of us on Windows the golang_org
folder can be found at C:\Go\src\vendor
I symlinked and I still get errors like
usr/local/Cellar/go/1.8/libexec/src/crypto/tls/key_agreement.go:20:2: could not import golang_org/x/crypto/curve25519 (cannot find package "golang_org/x/crypto/curve25519" in any of:
/usr/local/Cellar/go/1.8/libexec/src/golang_org/x/crypto/curve25519 (from $GOROOT)