forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.process.go
123 lines (112 loc) · 3.02 KB
/
request.process.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package network
import (
"fmt"
"github.com/yaoapp/gou"
)
// ProcessPost xiang.helper.Post HTTP Post
func ProcessPost(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPost(url, data, headers)
}
// ProcessPostJSON xiang.helper.PostJSON HTTP Post
func ProcessPostJSON(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPostJSON(url, data, headers)
}
// ProcessPut xiang.helper.Put HTTP PUT
func ProcessPut(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPut(url, data, headers)
}
// ProcessPutJSON xiang.helper.PutJSON HTTP PUT
func ProcessPutJSON(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPutJSON(url, data, headers)
}
// ProcessSend xiang.helper.Send HTTP Send
func ProcessSend(process *gou.Process) interface{} {
process.ValidateArgNums(2)
var data interface{}
var params = map[string]interface{}{}
var headers = map[string]string{}
method := process.ArgsString(0)
url := process.ArgsString(1)
if process.NumOfArgs() > 2 {
params = process.ArgsMap(2)
}
if process.NumOfArgs() > 3 {
data = process.Args[3]
}
if process.NumOfArgs() > 4 {
inputHeaders := process.ArgsMap(4)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestSend(method, url, params, data, headers)
}
// ProcessGet xiang.helper.Get HTTP Get
func ProcessGet(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var params = map[string]interface{}{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
params = process.ArgsMap(1)
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestGet(url, params, headers)
}