urlKit

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachQueryParamsToRawQuery added in v2.0.15

func AttachQueryParamsToRawQuery(rawQuery string, queryParams map[string]string) string

AttachQueryParamsToRawQuery

@param rawQuery 可能为""

func AttachQueryParamsToUrl added in v2.0.13

func AttachQueryParamsToUrl(url string, queryParams map[string]string) string

AttachQueryParamsToUrl

@param url (1) 原则上,不能为"",应该以"http://"或"https://"开头

(2) 不能是Request.URL.RawQuery

func DecodeURIComponent

func DecodeURIComponent(text string) (string, error)

DecodeURIComponent 解码

e.g. ("") => "", nil

func EncodeURIComponent

func EncodeURIComponent(text string) string

EncodeURIComponent 编码

e.g. ("") => ""

func Parse

func Parse(rawURL string) (*url.URL, error)

Parse 解析url(http、https、rtsp、rtmp等协议)

参考: https://blog.csdn.net/zhuyuqiang1238/article/details/121807708

@param rawURL !!!不能是如下格式: "localhost:8080"

e.g.

u, err := urlKit.Parse("http://localhost:8080/go?a=123&b=456")
if err != nil {
	panic(err)
}
fmt.Println(u.Scheme)     // http
fmt.Println(u.Host)       // localhost:8080
fmt.Println(u.Hostname()) // localhost
fmt.Println(u.Port())     // 8080
fmt.Println(u.Path)       // /go
fmt.Println(u.RawQuery)   // a=123&b=456
fmt.Println(u.Query())    // map[a:[123] b:[456]]

func ParseQuery

func ParseQuery(query string) (url.Values, error)

ParseQuery

e.g.

u, err := urlKit.Parse("http://localhost:8080/go?a=123&b=456")
if err != nil {
	panic(err)
}
fmt.Println(u.RawQuery) // a=123&b=456

m, err := urlKit.ParseQuery(u.RawQuery)
if err != nil {
	panic(err)
}
fmt.Println(m) 			// map[a:[123] b:[456]]

func ToBodyString added in v2.0.13

func ToBodyString(postParams map[string]string) string

func ToQueryString

func ToQueryString(queryParams map[string]string) string

ToQueryString

@param m 会对值进行 编码 操作 @return 可能为""

e.g.

(nil) => ""

e.g.1

m := map[string]string{
	"a": "test",
	"b": "测试",
}
fmt.Println(urlKit.ToQueryString(m)) // a=test&b=%E6%B5%8B%E8%AF%95

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL