go url parse

url = schema(http/https) + "//" + host(ip:port/domain:port) + path(/xxx) + "?" + rawQuery(xxx=xxx)

package main

import (
	"fmt"
	"net/url"
)

func parseUrlInfo(urlStr string) {
	u, err := url.Parse(urlStr)
	if err != nil {
		fmt.Printf("parse url %s failed: %v\n", urlStr, err)
		return
	}
	fmt.Printf("schema:%s host:%s path:%s rawQuery:%s\n", u.Scheme, u.Host, u.Path, u.RawQuery)
}

func main() {
	parseUrlInfo("http://127.0.0.1:1000/index.html?a=b")
	parseUrlInfo("https://www.baidu.com/index.html?a=b")
}

 

 

但是,在k8s restclient.Config中,没有schema,Host是https://xxx:xxx,APIPath是/xxx。

posted on 2025-06-22 11:50  王景迁  阅读(16)  评论(0)    收藏  举报

导航