-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
72 lines (57 loc) · 1.22 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package plugin_go
import (
"encoding/json"
"fmt"
"math/rand"
"net/url"
"strings"
)
type meta string
func (h meta) output(key, val string) {
fmt.Printf("%s: %s: %s\n", string(h), key, val)
}
func (h meta) parse(line string) (key, val string) {
if line == "" {
return
}
if len(line) < len(string(h)) {
return
}
if line[0:len(string(h))] != string(h) {
return
}
line = line[len(string(h))+2:]
end := strings.IndexByte(line, ':')
if end < 0 {
return
}
return line[0:end], line[end+2:]
}
var _letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-")
func randstr(n int) string {
b := make([]rune, n)
l := len(_letters)
for i := range b {
b[i] = _letters[rand.Intn(l)]
}
return string(b)
}
// 解析url参数
func GetUrlParams(_url string) (_json any) {
//解析URL
parsedURL, _ := url.Parse(_url)
// 获取URL参数
params, _ := url.ParseQuery(parsedURL.RawQuery)
// 将参数转换为JSON对象
jsonObj := make(map[string]interface{})
for key, values := range params {
if len(values) > 0 {
jsonObj[key] = values[0]
}
}
// 将JSON对象序列化为字符串
jsonBytes, _ := json.Marshal(jsonObj)
//转换为json对象
json.Unmarshal(jsonBytes, &_json)
return
}