-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
send_formvalues.go
49 lines (43 loc) · 1.17 KB
/
send_formvalues.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
package hit
import (
"github.com/Eun/go-hit/httpbody"
"github.com/Eun/go-hit/internal/converter"
)
// ISendFormValues provides methods to send form values.
type ISendFormValues interface {
// Add adds the specified value to the specified form value.
//
// Usage:
// Send().Body().FormValues("username").Add("admin")
Add(value ...interface{}) IStep
}
type sendFormValuesValueCallback func(hit Hit) *httpbody.URLValues
type sendFormValues struct {
cleanPath callPath
valueCallback sendFormValuesValueCallback
name string
}
func newSendFormValues(clearPath callPath, valueCallback sendFormValuesValueCallback, name string) ISendFormValues {
return &sendFormValues{
cleanPath: clearPath,
valueCallback: valueCallback,
name: name,
}
}
func (hdr *sendFormValues) Add(values ...interface{}) IStep {
return &hitStep{
Trace: ett.Prepare(),
When: SendStep,
CallPath: hdr.cleanPath.Push("Add", values),
Exec: func(hit *hitImpl) error {
for _, value := range values {
var s string
if err := converter.Convert(value, &s); err != nil {
return err
}
hdr.valueCallback(hit).Add(hdr.name, s)
}
return nil
},
}
}