diff options
| author | Shulhan <ms@kilabit.info> | 2021-09-23 16:32:45 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-09-23 16:40:55 +0700 |
| commit | 29ce1f01025b5773f72ac60ce5c6738cab4796f6 (patch) | |
| tree | 7ab81e868c555ec9c2a82e0f071bf941c13073cd | |
| parent | fcb5f55e5c10dec03ecf6256a46d3520a9affc61 (diff) | |
| download | gorankusu-29ce1f01025b5773f72ac60ce5c6738cab4796f6.tar.xz | |
all: convert the params to JSON object
Since the HttpTarget Params type changes to KeyFormInput, we cannot
use the Params directly but need to convert it JSON object first
using map[string]interface{}.
| -rw-r--r-- | key_form_input.go | 18 | ||||
| -rw-r--r-- | trunks.go | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/key_form_input.go b/key_form_input.go index 958c9a6..5a58beb 100644 --- a/key_form_input.go +++ b/key_form_input.go @@ -3,6 +3,8 @@ package trunks import ( "net/http" "net/url" + + "github.com/shuLhan/share/lib/math/big" ) // @@ -26,6 +28,22 @@ func (kfi KeyFormInput) ToHttpHeader() (headers http.Header) { } // +// ToJsonObject convert the KeyFormInput into JSON object. +// +func (kfi KeyFormInput) ToJsonObject() (data map[string]interface{}) { + data = make(map[string]interface{}, len(kfi)) + for k, fi := range kfi { + switch fi.Kind { + case FormInputKindNumber: + data[k], _ = big.NewRat(fi.Value).Float64() + default: + data[k] = fi.Value + } + } + return data +} + +// // ToMultipartFormData convert the KeyFormInput into map of string and raw // bytes. // @@ -530,7 +530,7 @@ func (trunks *Trunks) runHttpTarget(rr *RunRequest) (res *RunResponse, err error ) if rr.HttpTarget.RequestType == libhttp.RequestTypeJSON { - params = rr.HttpTarget.Params + params = rr.HttpTarget.Params.ToJsonObject() } else { params = rr.HttpTarget.Params.ToUrlValues() } |
