Fmt and docs

This commit is contained in:
Denis Makogon
2017-10-07 02:59:08 +03:00
parent 6141344e5f
commit e4684096f7
3 changed files with 24 additions and 23 deletions

View File

@@ -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
}

View File

@@ -2,19 +2,23 @@ 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,

View File

@@ -78,22 +78,19 @@ Fn accepts request data of the following format:
```json
{
"body": {
"some": "input"
}
}
```
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: