diff options
author | Wolfy-J <[email protected]> | 2018-05-31 14:10:59 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-05-31 14:10:59 +0300 |
commit | 48f4f7a39a2336be24cc74b4116c02cc941dbd9a (patch) | |
tree | 3de1d379e43fe0772fb699852eac08ded6bbe644 /http/post.go | |
parent | ec2af29c17402145547699e719902d0f3f2ec8ec (diff) |
http support
Diffstat (limited to 'http/post.go')
-rw-r--r-- | http/post.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/http/post.go b/http/post.go new file mode 100644 index 00000000..64c60d98 --- /dev/null +++ b/http/post.go @@ -0,0 +1,45 @@ +package http + +import "strings" + +type postData map[string]interface{} + +func (d postData) push(k string, v []string) { + if len(v) == 0 { + // doing nothing + return + } + + chunks := make([]string, 0) + for _, chunk := range strings.Split(k, "[") { + chunks = append(chunks, strings.Trim(chunk, "]")) + } + + d.pushChunk(chunks, v) +} + +func (d postData) pushChunk(k []string, v []string) { + if len(v) == 0 || v[0] == "" { + return + } + + head := k[0] + tail := k[1:] + if len(k) == 1 { + d[head] = v[0] + return + } + + // unnamed array + if len(tail) == 1 && tail[0] == "" { + d[head] = v + return + } + + if p, ok := d[head]; !ok { + d[head] = make(postData) + d[head].(postData).pushChunk(tail, v) + } else { + p.(postData).pushChunk(tail, v) + } +} |