r.go 821 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4
package application

import (
	"fmt"
Y
Your Name 已提交
5
	goku_plugin "github.com/eolinker/goku-plugin"
E
eoLinker API Management 已提交
6 7 8 9 10
	"net/http"
	"net/url"
	"time"
)

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

	if backendDomain == "" {
Y
Your Name 已提交
14
		return nil, fmt.Errorf("invaild url")
E
eoLinker API Management 已提交
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

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

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

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

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