diff options
Diffstat (limited to 'key_form_input.go')
| -rw-r--r-- | key_form_input.go | 18 |
1 files changed, 18 insertions, 0 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. // |
