在 URL 中,权限应该是可选的,这意味着诸如此类的 URLmailto:John.Doe@example.com是有效的。
在 Golang 1.15.2 中,如果使用net/url该类创建上述 URL,则似乎不允许在没有权限的情况下创建 URL。
例如
package main
import (
"fmt"
"net/url"
)
func main() {
var theURL = url.URL{}
theURL.Scheme = "mailto"
theURL.Path = "John.Doe@example.com"
fmt.Println(theURL.String()) // should be mailto:John.Doe@example.com, but is mailto://John.Doe@example.com
}
Run Code Online (Sandbox Code Playgroud)
我在这里遗漏了什么还是这在技术上是一个错误?
使用theURL.Opaque代替theURL.Path。见 https://golang.org/pkg/net/url/#URL
方案后不以斜杠开头的 URL 被解释为:
Run Code Online (Sandbox Code Playgroud)scheme:opaque[?query][#fragment]
Go Playground 中的工作代码:https : //play.golang.org/p/TFATDQu4PHc