如果您这样做:
_, err := http.Get("google.com")
if err != nil {
log.Fatal(err)
}
你得到的输出:
2021/08/05 15:42:18 Get "google.com": unsupported protocol scheme ""
我想知道如何获取错误类型,以便我可以像这样处理错误:
if errors.Is(err, "unsupported protocol scheme") {
//add protocol scheme to url string
}
我试过 fmt。Printf(“%#v”,错误),它给出了:
&url.Error{Op:"Get", URL:"google.com", Err:(*errors.errorString)(0xc000098c40)}
断续器打印(“%T”)给出:
*url.Error
编辑:如果你投了反对票,我非常感谢你的想法。
大话西游666
斯蒂芬大帝
森栏
随时随地看视频慕课网APP
相关分类