From e4684096f737d402287e8e91cb863ebe9dbbea36 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Sat, 7 Oct 2017 02:59:08 +0300 Subject: [PATCH] Fmt and docs --- api/agent/protocol/json.go | 4 ++-- api/agent/protocol/json_test.go | 36 ++++++++++++++++++--------------- docs/function-format.md | 7 ++----- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/api/agent/protocol/json.go b/api/agent/protocol/json.go index 8d934159d..42a040268 100644 --- a/api/agent/protocol/json.go +++ b/api/agent/protocol/json.go @@ -42,17 +42,17 @@ func (h *JSONProtocol) DumpJSON(req *http.Request) error { } err = writeString(err, h.in, "{") err = writeString(err, h.in, `"body":`) - err = stdin.Encode(bb.String()) if err != nil { return err } + err = stdin.Encode(bb.String()) err = writeString(err, h.in, ",") defer bb.Reset() err = writeString(err, h.in, `"headers":`) - err = stdin.Encode(req.Header) if err != nil { return err } + err = stdin.Encode(req.Header) err = writeString(err, h.in, "}") return err } diff --git a/api/agent/protocol/json_test.go b/api/agent/protocol/json_test.go index 19391b429..cbe21e000 100644 --- a/api/agent/protocol/json_test.go +++ b/api/agent/protocol/json_test.go @@ -2,33 +2,37 @@ package protocol import ( "bytes" - "testing" + "encoding/json" + "io" + "io/ioutil" "net/http" "net/url" - "io/ioutil" - "io" - "encoding/json" "reflect" + "testing" ) type RequestData struct { A string `json:"a"` } +type fuckReed struct { + Body RequestData `json:"body"` +} + func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) { req := &http.Request{ Method: http.MethodPost, URL: &url.URL{ - Scheme: "http", - Host: "localhost:8080", - Path: "/v1/apps", + Scheme: "http", + Host: "localhost:8080", + Path: "/v1/apps", RawQuery: "something=something&etc=etc", }, ProtoMajor: 1, ProtoMinor: 1, Header: http.Header{ - "Host": []string{"localhost:8080"}, - "User-Agent": []string{"curl/7.51.0"}, + "Host": []string{"localhost:8080"}, + "User-Agent": []string{"curl/7.51.0"}, "Content-Type": []string{"application/json"}, }, Host: "localhost:8080", @@ -39,7 +43,7 @@ func TestJSONProtocolDumpJSONRequestWithData(t *testing.T) { req.Body = ioutil.NopCloser(&buf) r, w := io.Pipe() - proto := JSONProtocol{w,r} + proto := JSONProtocol{w, r} go func() { err := proto.DumpJSON(req) if err != nil { @@ -73,16 +77,16 @@ func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) { req := &http.Request{ Method: http.MethodPost, URL: &url.URL{ - Scheme: "http", - Host: "localhost:8080", - Path: "/v1/apps", + Scheme: "http", + Host: "localhost:8080", + Path: "/v1/apps", RawQuery: "something=something&etc=etc", }, ProtoMajor: 1, ProtoMinor: 1, Header: http.Header{ - "Host": []string{"localhost:8080"}, - "User-Agent": []string{"curl/7.51.0"}, + "Host": []string{"localhost:8080"}, + "User-Agent": []string{"curl/7.51.0"}, "Content-Type": []string{"application/json"}, }, Host: "localhost:8080", @@ -91,7 +95,7 @@ func TestJSONProtocolDumpJSONRequestWithoutData(t *testing.T) { req.Body = ioutil.NopCloser(&buf) r, w := io.Pipe() - proto := JSONProtocol{w,r} + proto := JSONProtocol{w, r} go func() { err := proto.DumpJSON(req) if err != nil { diff --git a/docs/function-format.md b/docs/function-format.md index e47fbc5da..d110b9d44 100644 --- a/docs/function-format.md +++ b/docs/function-format.md @@ -78,9 +78,7 @@ Fn accepts request data of the following format: ```json { - "body": { - "some": "input" - } + "some": "input" } ``` @@ -88,12 +86,11 @@ Internally function receives data in following format: ```json { - "body": "{\"some\":\"data\"}\n", + "body": "{\"some\":\"input\"}\n", "headers": { "yo": ["dawg"] } } - ``` Function's output format should have following format: