r.go 729 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9
package application

import (
	"fmt"
	"net/http"
	"net/url"
	"time"
)

Y
Your Name 已提交
10
func request(method string, backendDomain string, query url.Values, header http.Header, body []byte, timeout time.Duration) (*http.Response, error) {
E
eoLinker API Management 已提交
11 12

	if backendDomain == "" {
Y
Your Name 已提交
13
		return nil, fmt.Errorf("invaild url")
E
eoLinker API Management 已提交
14 15 16 17 18 19 20
	}

	u, err := url.ParseRequestURI(backendDomain)
	if err != nil {

		return nil, err
	}
Y
Your Name 已提交
21
	u.Query()
E
eoLinker API Management 已提交
22 23 24
	req, err := NewRequest(method, u)
	if err != nil {

Y
Your Name 已提交
25
		return nil, err
E
eoLinker API Management 已提交
26
	}
Y
Your Name 已提交
27 28 29 30 31 32 33 34
	queryDest:= u.Query()
	if query!= nil{
		for k,vs:=range query{
			for _,v:=range vs{
				queryDest.Add(k,v)
			}
		}
	}
E
eoLinker API Management 已提交
35

Y
Your Name 已提交
36
	req.headers = header
E
eoLinker API Management 已提交
37

Y
Your Name 已提交
38
	req.queryParams = queryDest
E
eoLinker API Management 已提交
39 40 41 42 43

	req.SetRawBody(body)
	if timeout != 0 {
		req.SetTimeout(timeout)
	}
Y
Your Name 已提交
44 45
	return req.Send()
}