mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
fix: fix issue #292, change query params type to map[string][]string
This commit is contained in:
@@ -48,6 +48,9 @@ import (
|
||||
- [UploadFile](#UploadFile)
|
||||
- [IsPingConnected](#IsPingConnected)
|
||||
- [IsTelnetConnected](#IsTelnetConnected)
|
||||
- [IsTelnetConnected](#IsTelnetConnected)
|
||||
- [BuildUrl](#BuildUrl)
|
||||
- [AddQueryParams](#AddQueryParams)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -1031,3 +1034,83 @@ func main() {
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="BuildUrl">BuildUrl</span>
|
||||
|
||||
<p>创建url字符串。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func BuildUrl(scheme, host, path string, query map[string][]string) (string, error)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
urlStr, err := netutil.BuildUrl(
|
||||
"https",
|
||||
"example.com",
|
||||
"query",
|
||||
map[string][]string{
|
||||
"a": {"foo", "bar"},
|
||||
"b": {"baz"},
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(urlStr)
|
||||
fmt.Println(err)
|
||||
|
||||
// Output:
|
||||
// https://example.com/query?a=foo&a=bar&b=baz
|
||||
// <nil>
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="AddQueryParams">AddQueryParams</span>
|
||||
|
||||
<p>向url添加查询参数。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func AddQueryParams(urlStr string, params map[string][]string) (string, error)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
urlStr, err := netutil.BuildUrl(
|
||||
"https",
|
||||
"example.com",
|
||||
"query",
|
||||
map[string][]string{
|
||||
"a": {"foo", "bar"},
|
||||
"b": {"baz"},
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(urlStr)
|
||||
fmt.Println(err)
|
||||
|
||||
// Output:
|
||||
// https://example.com/query?a=foo&a=bar&b=baz
|
||||
// <nil>
|
||||
}
|
||||
```
|
||||
@@ -48,6 +48,9 @@ import (
|
||||
- [UploadFile](#UploadFile)
|
||||
- [IsPingConnected](#IsPingConnected)
|
||||
- [IsTelnetConnected](#IsTelnetConnected)
|
||||
- [BuildUrl](#BuildUrl)
|
||||
- [AddQueryParams](#AddQueryParams)
|
||||
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -1031,3 +1034,83 @@ func main() {
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="BuildUrl">BuildUrl</span>
|
||||
|
||||
<p>Builds a URL from the given params.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func BuildUrl(scheme, host, path string, query map[string][]string) (string, error)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
urlStr, err := netutil.BuildUrl(
|
||||
"https",
|
||||
"example.com",
|
||||
"query",
|
||||
map[string][]string{
|
||||
"a": {"foo", "bar"},
|
||||
"b": {"baz"},
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(urlStr)
|
||||
fmt.Println(err)
|
||||
|
||||
// Output:
|
||||
// https://example.com/query?a=foo&a=bar&b=baz
|
||||
// <nil>
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="AddQueryParams">AddQueryParams</span>
|
||||
|
||||
<p>Adds query parameters to the given URL.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func AddQueryParams(urlStr string, params map[string][]string) (string, error)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
urlStr, err := netutil.BuildUrl(
|
||||
"https",
|
||||
"example.com",
|
||||
"query",
|
||||
map[string][]string{
|
||||
"a": {"foo", "bar"},
|
||||
"b": {"baz"},
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(urlStr)
|
||||
fmt.Println(err)
|
||||
|
||||
// Output:
|
||||
// https://example.com/query?a=foo&a=bar&b=baz
|
||||
// <nil>
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user