💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### URL参数排序 ```go // url query 参数key排序(按key升序) var u1 = "https://www.baidu.com/?userId=admin&name=john&order=1&auto=2" u, err := url.Parse(u1) if err != nil { fmt.Println("err", err.Error()) return } s := u.Query().Encode() fmt.Printf("query:%s\n", s) // 自行拼接参数 values := url.Values{} values.Set("d", "vd") values.Set("c", "vc") values.Set("b", "vb") values.Set("a", "va") fmt.Printf("values:%s\n", values.Encode()) ``` ``` query:auto=2&name=john&order=1&userId=admin values:a=va&b=vb&c=vc&d=vd ``` ### URL编码与解码 ```go urlStr := "你好,世界!" escapeUrl := url.QueryEscape(urlStr) fmt.Printf("url encode:%s\n", escapeUrl) enEscapeUrl, _ := url.QueryUnescape(escapeUrl) fmt.Printf("url decode:%s\n", enEscapeUrl) ``` ``` url encode:%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C%EF%BC%81 url decode:你好,世界! ```