2014-04-14 23 views
1

在下面的example中,結尾的URL /被刪除,有沒有辦法保留/如何避免當在解析引用中去掉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 

回答

1

我想出了答案,這是不使用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/