From 9c90e22b8591629750287f437807649ea1628401 Mon Sep 17 00:00:00 2001 From: David Bayo Alcaide Date: Fri, 16 Feb 2018 20:32:15 +0100 Subject: [PATCH] body module --- binding/body.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 binding/body.go diff --git a/binding/body.go b/binding/body.go new file mode 100644 index 00000000..350f48bf --- /dev/null +++ b/binding/body.go @@ -0,0 +1,30 @@ +package binding + +import "net/url" + +// Body type map[string]interface{} +type Body map[string]interface{} + +// ToBody transforms object into Body type. +func ToBody(in interface{}) *Body { + switch in.(type) { + case Body: + res := in.(Body) + + return &res + case url.Values: + result := make(Body) + + for key, value := range in.(url.Values) { + if len(value) == 1 { + result[key] = value[0] + } else { + result[key] = value + } + } + + return &result + } + + return new(Body) +}