/
gout.go
80 lines (68 loc) · 1.8 KB
/
gout.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
package dataflow
import (
"net/http"
)
// Gout is the data structure at the beginning of everything
type Gout struct {
*http.Client
DataFlow // TODO 优化
}
var (
// DefaultClient The default http client, which has a connection pool
DefaultClient = http.Client{}
// DefaultBenchClient is the default http client used by the benchmark,
// which has a connection pool
DefaultBenchClient = http.Client{
Transport: &http.Transport{
MaxIdleConnsPerHost: 10000,
},
}
)
// New function is mainly used when passing custom http client
func New(c ...*http.Client) *Gout {
out := &Gout{}
if len(c) == 0 || c[0] == nil {
out.Client = &DefaultClient
} else {
out.Client = c[0]
}
out.DataFlow.out = out
out.DataFlow.Req.g = out
return out
}
// TODO 这一层可以直接删除
// v0.3.3版本开始算起, v0.3.7版本将会删除
// GET send HTTP GET method
func GET(url string) *DataFlow {
return New().GET(url)
}
// POST send HTTP POST method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func POST(url string) *DataFlow {
return New().POST(url)
}
// PUT send HTTP PUT method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func PUT(url string) *DataFlow {
return New().PUT(url)
}
// DELETE send HTTP DELETE method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func DELETE(url string) *DataFlow {
return New().DELETE(url)
}
// PATCH send HTTP PATCH method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func PATCH(url string) *DataFlow {
return New().PATCH(url)
}
// HEAD send HTTP HEAD method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func HEAD(url string) *DataFlow {
return New().HEAD(url)
}
// OPTIONS send HTTP OPTIONS method
// v0.3.3版本开始算起, v0.3.7版本将会删除
func OPTIONS(url string) *DataFlow {
return New().OPTIONS(url)
}