aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-09-23 16:32:45 +0700
committerShulhan <ms@kilabit.info>2021-09-23 16:40:55 +0700
commit29ce1f01025b5773f72ac60ce5c6738cab4796f6 (patch)
tree7ab81e868c555ec9c2a82e0f071bf941c13073cd
parentfcb5f55e5c10dec03ecf6256a46d3520a9affc61 (diff)
downloadgorankusu-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.go18
-rw-r--r--trunks.go2
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.
//
diff --git a/trunks.go b/trunks.go
index 8952b5c..44d6400 100644
--- a/trunks.go
+++ b/trunks.go
@@ -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()
}