Go实例: URL Parsing

Rachel ·
更新时间:2024-11-13
· 523 次阅读

package main import ( "fmt" "net" "net/url" ) func main() { s := "postgres://user:pass@host.com:5432/path?k=v#f" u, err := url.Parse(s) if err != nil { panic(err) } fmt.Println(u.Scheme) fmt.Println(u.User) fmt.Println(u.User.Username()) p, _ := u.User.Password() fmt.Println(p) fmt.Println(u.Host) host, port, _ := net.SplitHostPort(u.Host) fmt.Println(host) fmt.Println(port) fmt.Println(u.Path) fmt.Println(u.Fragment) fmt.Println(u.RawQuery) m, _ := url.ParseQuery(u.RawQuery) fmt.Println(m) fmt.Println(m["k"][0]) }$ go run url-parsing.go postgres user:pass user pass host.com:5432 host.com 5432 /path f k=v map[k:[v]] v



GO实例 GO url

需要 登录 后方可回复, 如果你还没有账号请 注册新账号