From 29ce1f01025b5773f72ac60ce5c6738cab4796f6 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 23 Sep 2021 16:32:45 +0700 Subject: 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{}. --- key_form_input.go | 18 ++++++++++++++++++ trunks.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) 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" ) // @@ -25,6 +27,22 @@ func (kfi KeyFormInput) ToHttpHeader() (headers http.Header) { return headers } +// +// 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() } -- cgit v1.3