Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http 如何避免在Go中解析引用时删除URL斜杠的结尾_Http_Url_Path_Go - Fatal编程技术网

Http 如何避免在Go中解析引用时删除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)) } 输

在下面的例子中,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))
}
输出:

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/