在 URL 中,權限應該是可選的,這意味著諸如此類的 URLmailto:[email protected]是有效的。在 Golang 1.15.2 中,如果使用net/url該類創建一個像上面這樣的 URL,它似乎不允許在沒有權限的情況下創建 URL。例如package mainimport ( "fmt" "net/url")func main() { var theURL = url.URL{} theURL.Scheme = "mailto" theURL.Path = "[email protected]" fmt.Println(theURL.String()) // should be mailto:[email protected], but is mailto://[email protected]}我在這里遺漏了什么或者這在技術上是一個錯誤嗎?
1 回答

一只名叫tom的貓
TA貢獻1906條經驗 獲得超3個贊
使用theURL.Opaque
而不是theURL.Path
. 見 https://golang.org/pkg/net/url/#URL
方案后不以斜杠開頭的 URL 被解釋為:
scheme:opaque[?query][#fragment]
Go Playground 中的工作代碼:https: //play.golang.org/p/TFATDQu4PHc
- 1 回答
- 0 關注
- 92 瀏覽
添加回答
舉報
0/150
提交
取消