Skip to content

Commit b0fc974

Browse files
author
Montana Flynn
committed
Add some line breaks for code readability
1 parent 648be8c commit b0fc974

22 files changed

+151
-20
lines changed

src/targets/go/native.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,54 +44,57 @@ module.exports = function (source, options) {
4444

4545
code.push(')\n')
4646

47-
code.push('func main() {')
47+
code.push('func main() {\n')
4848

4949
// Create client
5050
if (opts.timeout > 0) {
5151
code.push('\tclient := http.Client{')
5252
code.push(util.format('\t\tTimeout: time.Duration(%s * time.Second),', opts.timeout))
53-
code.push('\t}')
53+
code.push('\t}\n')
5454
} else {
55-
code.push('\tclient := &http.Client{}')
55+
code.push('\tclient := &http.Client{}\n')
5656
}
5757

58-
code.push(util.format('\turl := "%s"', source.fullUrl))
58+
code.push(util.format('\turl := "%s"\n', source.fullUrl))
5959

6060
// If we have body content or not create the var and reader or nil
6161
if (source.postData.text) {
62-
code.push(util.format('\tpayload := strings.NewReader(%s)', JSON.stringify(source.postData.text)))
63-
code.push(util.format('\treq, %s := http.NewRequest("%s", url, payload)', errorPlaceholder, source.method))
62+
code.push(util.format('\tpayload := strings.NewReader(%s)\n', JSON.stringify(source.postData.text)))
63+
code.push(util.format('\treq, %s := http.NewRequest("%s", url, payload)\n', errorPlaceholder, source.method))
6464
} else {
65-
code.push(util.format('\treq, %s := http.NewRequest("%s", url, nil)', errorPlaceholder, source.method))
65+
code.push(util.format('\treq, %s := http.NewRequest("%s", url, nil)\n', errorPlaceholder, source.method))
6666
}
6767

6868
errorCheck()
6969

7070
// Add headers
71-
Object.keys(source.allHeaders).map(function (key) {
72-
code.push(util.format('\treq.Header.Add("%s", "%s")', key, source.allHeaders[key]))
73-
})
71+
if (Object.keys(source.allHeaders).length) {
72+
Object.keys(source.allHeaders).map(function (key) {
73+
code.push(util.format('\treq.Header.Add("%s", "%s")', key, source.allHeaders[key]))
74+
})
75+
code.push(null)
76+
}
7477

7578
// Make request
7679
code.push(util.format('\tres, %s := client.Do(req)', errorPlaceholder))
7780
errorCheck()
7881

7982
// Get Body
8083
if (opts.printBody) {
81-
code.push('\tdefer res.Body.Close()')
84+
code.push('\n\tdefer res.Body.Close()')
8285
code.push(util.format('\tbody, %s := ioutil.ReadAll(res.Body)', errorPlaceholder))
8386
errorCheck()
8487
}
8588

8689
// Print it
87-
code.push('\tfmt.Println(res)')
90+
code.push('\n\tfmt.Println(res)')
8891

8992
if (opts.printBody) {
9093
code.push('\tfmt.Println(string(body))')
9194
}
9295

9396
// End main block
94-
code.push('}')
97+
code.push('\n}')
9598

9699
return code.join('\n')
97100
}

src/targets/python/python3.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ module.exports = function (source, options) {
1010
// Check which protocol to be used for the client connection
1111
var protocol = source.uriObj.protocol
1212
if (protocol === 'https:') {
13-
code.push(util.format('conn = http.client.HTTPSConnection("%s")', source.uriObj.host))
13+
code.push(util.format('conn = http.client.HTTPSConnection("%s")\n', source.uriObj.host))
1414
} else {
15-
code.push(util.format('conn = http.client.HTTPConnection("%s")', source.uriObj.host))
15+
code.push(util.format('conn = http.client.HTTPConnection("%s")\n', source.uriObj.host))
1616
}
1717

1818
// Create payload string if it exists
1919
var payload = JSON.stringify(source.postData.text)
2020
if (payload) {
21-
code.push(util.format('payload = %s', payload))
21+
code.push(util.format('payload = %s\n', payload))
2222
}
2323

2424
// Create Headers
@@ -27,7 +27,7 @@ module.exports = function (source, options) {
2727
var headerCount = Object.keys(headers).length
2828
if (headerCount === 1) {
2929
for (header in headers) {
30-
code.push(util.format('headers = { \'%s\': "%s" }', header, headers[header]))
30+
code.push(util.format('headers = { \'%s\': "%s" }\n', header, headers[header]))
3131
}
3232
} else if (headerCount > 1) {
3333
var headerLine
@@ -41,7 +41,7 @@ module.exports = function (source, options) {
4141
}
4242
code.push(headerLine)
4343
}
44-
code.push(' }')
44+
code.push(' }\n')
4545
}
4646

4747
// Make Request
@@ -58,9 +58,9 @@ module.exports = function (source, options) {
5858
}
5959

6060
// Get Response
61-
code.push('res = conn.getresponse()')
61+
code.push('\nres = conn.getresponse()')
6262
code.push('data = res.read()')
63-
code.push('print(res.status)')
63+
code.push('\nprint(res.status)')
6464
code.push('print(data)')
6565

6666
// console.log(code)

test/fixtures/output/go/native/application-form-encoded.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har"
15+
1316
payload := strings.NewReader("foo=bar&hello=world")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("content-type", "application/x-www-form-urlencoded")
21+
1622
res, _ := client.Do(req)
23+
1724
defer res.Body.Close()
1825
body, _ := ioutil.ReadAll(res.Body)
26+
1927
fmt.Println(res)
2028
fmt.Println(string(body))
29+
2130
}

test/fixtures/output/go/native/application-json.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har"
15+
1316
payload := strings.NewReader("{\"number\": 1, \"string\": \"f\\\"oo\", \"arr\": [1, 2, 3], \"nested\": {\"a\": \"b\"}, \"arr_mix\": [1, \"a\", {\"arr_mix_nested\": {}}] }")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("content-type", "application/json")
21+
1622
res, _ := client.Do(req)
23+
1724
defer res.Body.Close()
1825
body, _ := ioutil.ReadAll(res.Body)
26+
1927
fmt.Println(res)
2028
fmt.Println(string(body))
29+
2130
}

test/fixtures/output/go/native/cookies.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ import (
77
)
88

99
func main() {
10+
1011
client := &http.Client{}
12+
1113
url := "http://mockbin.com/har"
14+
1215
req, _ := http.NewRequest("POST", url, nil)
16+
1317
req.Header.Add("cookie", "foo=bar; bar=baz")
18+
1419
res, _ := client.Do(req)
20+
1521
defer res.Body.Close()
1622
body, _ := ioutil.ReadAll(res.Body)
23+
1724
fmt.Println(res)
1825
fmt.Println(string(body))
26+
1927
}

test/fixtures/output/go/native/full.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"
15+
1316
payload := strings.NewReader("foo=bar")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("cookie", "foo=bar; bar=baz")
1621
req.Header.Add("accept", "application/json")
1722
req.Header.Add("content-type", "application/x-www-form-urlencoded")
23+
1824
res, _ := client.Do(req)
25+
1926
defer res.Body.Close()
2027
body, _ := ioutil.ReadAll(res.Body)
28+
2129
fmt.Println(res)
2230
fmt.Println(string(body))
31+
2332
}

test/fixtures/output/go/native/headers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ import (
77
)
88

99
func main() {
10+
1011
client := &http.Client{}
12+
1113
url := "http://mockbin.com/har"
14+
1215
req, _ := http.NewRequest("GET", url, nil)
16+
1317
req.Header.Add("accept", "application/json")
1418
req.Header.Add("x-foo", "Bar")
19+
1520
res, _ := client.Do(req)
21+
1622
defer res.Body.Close()
1723
body, _ := ioutil.ReadAll(res.Body)
24+
1825
fmt.Println(res)
1926
fmt.Println(string(body))
27+
2028
}

test/fixtures/output/go/native/multipart-data.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har"
15+
1316
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
21+
1622
res, _ := client.Do(req)
23+
1724
defer res.Body.Close()
1825
body, _ := ioutil.ReadAll(res.Body)
26+
1927
fmt.Println(res)
2028
fmt.Println(string(body))
29+
2130
}

test/fixtures/output/go/native/multipart-file.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har"
15+
1316
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
21+
1622
res, _ := client.Do(req)
23+
1724
defer res.Body.Close()
1825
body, _ := ioutil.ReadAll(res.Body)
26+
1927
fmt.Println(res)
2028
fmt.Println(string(body))
29+
2130
}

test/fixtures/output/go/native/multipart-form-data.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import (
88
)
99

1010
func main() {
11+
1112
client := &http.Client{}
13+
1214
url := "http://mockbin.com/har"
15+
1316
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--")
17+
1418
req, _ := http.NewRequest("POST", url, payload)
19+
1520
req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
21+
1622
res, _ := client.Do(req)
23+
1724
defer res.Body.Close()
1825
body, _ := ioutil.ReadAll(res.Body)
26+
1927
fmt.Println(res)
2028
fmt.Println(string(body))
29+
2130
}

0 commit comments

Comments
 (0)