为什么我会收到此代码的编译错误?响应类型在“net/http”中定义
package main
import "net/http"
func main() {
}
func GetWithProxy(urlString string, proxyString string) (resp *Response, err error) {
return nil, nil
}
错误:
.\t.go:3: imported and not used: "net/http"
.\t.go:7: undefined: Response
最佳答案
它在提示你没有使用 net/http
,而你没有。
package main
import "net/http"
func GetWithProxy(urlString string, proxyString string) (resp *http.Response, err error) {
return nil, nil
}
func main() {
}
这将编译,因为现在您正在使用 net/http
。编译器不知道您在谈论 net/http 的
Response
类型。
如果你想“吸收”net/http 的
命名空间,你可以这样做:
package main
import . "net/http"
func GetWithProxy(urlString string, proxyString string) (resp *Response, err error) {
return nil, nil
}
func main() {
}
关于http - 新手编译报错net/http响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40902533/