httplib_allied_creation_basic.go
1.2 KB
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
package service_gateway
import (
"time"
"github.com/astaxie/beego/httplib"
)
type HttplibAlliedCreationBasic struct {
connectTimeout time.Duration
readWriteTimeout time.Duration
BaseUrL string
}
func (gateway HttplibAlliedCreationBasic) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
request = httplib.Get(url)
case "post":
request = httplib.Post(url)
case "put":
request = httplib.Put(url)
case "delete":
request = httplib.Delete(url)
case "head":
request = httplib.Head(url)
default:
request = httplib.Get(url)
}
return request.SetTimeout(gateway.connectTimeout, gateway.readWriteTimeout)
}
func (gateway HttplibAlliedCreationBasic) getResponseData(result GatewayResponse) {
}
//GetDictionarysByCode 根据code获取字典数据
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param map[string]interface{}) error {
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
req := gateway.createRequest(url, "post")
req, err := req.JSONBody(param)
if err != nil {
return err
}
var result GatewayResponse
err = req.ToJSON(&result)
if err != nil {
return err
}
return nil
}