-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.go
83 lines (56 loc) · 1.35 KB
/
utilities.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
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/btcsuite/btcutil/base58"
"github.com/valyala/fasthttp"
)
func stringToBytes(text string) []byte {
var data []byte
data, err := hex.DecodeString(text)
if err != nil {
data = base58.Decode(text)
}
return data
}
func createRange(min, max int) []int {
var list = make([]int, max-min+1)
for i := range list {
list[i] = min + i
}
return list
}
func POST(url string, values map[string]interface{}) *fasthttp.Response {
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
req.SetRequestURI(url)
req.SetConnectionClose()
req.Header.SetMethod("POST")
req.Header.SetContentType("application/json")
kb, _ := json.Marshal(values)
req.SetBody(kb)
if err := client.Do(req, resp); err != nil {
panic(err)
}
defer fasthttp.ReleaseRequest(req)
return resp
}
func GET(url string, values map[string]interface{}) *fasthttp.Response {
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
url += "?"
for key, value := range values {
url += fmt.Sprintf("%s=%s&", key, value)
}
url = url[:len(url)-1]
req.SetRequestURI(url)
req.SetConnectionClose()
req.Header.SetMethod("GET")
req.Header.SetContentType("application/json")
if err := client.Do(req, resp); err != nil {
panic(err)
}
defer fasthttp.ReleaseRequest(req)
return resp
}