/
axapi_util.go
39 lines (35 loc) · 960 Bytes
/
axapi_util.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
package thunder
import (
"crypto/tls"
"io"
"net/http"
"time"
"util"
)
func doHttp(method string, host string, body io.Reader, headers map[string]string) (*http.Response, error) {
logger := util.GetLoggerInstance()
logger.Println(method, ">", host)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr, Timeout: 30 * time.Second}
req, err := http.NewRequest(method, host, body)
if err != nil {
logger.Println("failed to create new request")
}
for property, value := range headers {
req.Header.Set(property, value)
}
resp, err := client.Do(req)
if err != nil {
logger.Println("failed at http.Client.Do()")
}
return resp, err
}
func GetReqHeader(auth_token string) map[string]string {
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/json"
headers["Authorization"] = auth_token
return headers
}