aboutsummaryrefslogtreecommitdiff
path: root/key_form_input.go
diff options
context:
space:
mode:
Diffstat (limited to 'key_form_input.go')
-rw-r--r--key_form_input.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/key_form_input.go b/key_form_input.go
index 4922517..e457466 100644
--- a/key_form_input.go
+++ b/key_form_input.go
@@ -6,6 +6,7 @@ package trunks
import (
"net/http"
"net/url"
+ "strings"
"github.com/shuLhan/share/lib/math/big"
)
@@ -27,10 +28,25 @@ func (kfi KeyFormInput) ToHttpHeader() (headers http.Header) {
}
// ToJsonObject convert the KeyFormInput into JSON object.
+// FormInput with Kind is FormInputKindBoolean will be converted to true if
+// the Value is either "true", "yes", or "1".
func (kfi KeyFormInput) ToJsonObject() (data map[string]interface{}) {
+ var (
+ k string
+ fi FormInput
+ vstr string
+ )
+
data = make(map[string]interface{}, len(kfi))
- for k, fi := range kfi {
+ for k, fi = range kfi {
switch fi.Kind {
+ case FormInputKindBoolean:
+ vstr = strings.ToLower(fi.Value)
+ if vstr == `true` || vstr == `yes` || vstr == `1` {
+ data[k] = true
+ } else {
+ data[k] = false
+ }
case FormInputKindNumber:
data[k], _ = big.NewRat(fi.Value).Float64()
default: