Http 如何避免在Go中解析引用时删除URL斜杠的结尾
在下面的例子中,URL的末尾Http 如何避免在Go中解析引用时删除URL斜杠的结尾,http,url,path,go,Http,Url,Path,Go,在下面的例子中,URL的末尾/被删除,有没有办法保留/ package main import ( "fmt" "net/url" "path" ) func main() { u, _ := url.Parse("http://localhost:5100") relative, _ := url.Parse(path.Join("hello/")) fmt.Println(u.ResolveReference(relative)) } 输
/
被删除,有没有办法保留/
package main
import (
"fmt"
"net/url"
"path"
)
func main() {
u, _ := url.Parse("http://localhost:5100")
relative, _ := url.Parse(path.Join("hello/"))
fmt.Println(u.ResolveReference(relative))
}
输出:
http://localhost:5100/hello
http://localhost:5100/hello/
我找到了答案,那就是不要使用
path.Join
:
package main
import (
"fmt"
"net/url"
)
func main() {
u, _ := url.Parse("http://localhost:5100")
relative, _ := url.Parse("hello/")
fmt.Println(u.ResolveReference(relative))
}
输出:
http://localhost:5100/hello
http://localhost:5100/hello/