Skip to content

Commit cab17f7

Browse files
authored
Merge pull request #264 from tooolbox/fix/golang-multiline
Go: Use Multiline Strings for Raw Bodies
2 parents cf4acef + 7671c77 commit cab17f7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

codegens/golang/lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('./lodash'),
22
sanitize = require('./util').sanitize,
3+
sanitizeMultiline = require('./util').sanitizeMultiline,
34
sanitizeOptions = require('./util').sanitizeOptions,
45
addFormParam = require('./util').addFormParam,
56
isFile = false,
@@ -13,7 +14,7 @@ var _ = require('./lodash'),
1314
*/
1415
function parseRawBody (body, trim) {
1516
var bodySnippet;
16-
bodySnippet = `payload := strings.NewReader("${sanitize(body.toString(), trim)}")`;
17+
bodySnippet = `payload := strings.NewReader(\`${sanitizeMultiline(body.toString(), trim)}\`)`;
1718
return bodySnippet;
1819
}
1920

codegens/golang/lib/util.js

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ module.exports = {
1616

1717
},
1818

19+
/**
20+
* sanitizes input string by handling escape characters eg: converts '''' to '\'\''
21+
* and trim input if required
22+
*
23+
* @param {String} inputString
24+
* @param {Boolean} [trim] - indicates whether to trim string or not
25+
* @returns {String}
26+
*/
27+
sanitizeMultiline: function (inputString, trim) {
28+
if (typeof inputString !== 'string') {
29+
return '';
30+
}
31+
inputString = inputString.replace(/`/g, '`+"`"+`');
32+
return trim ? inputString.trim() : inputString;
33+
34+
},
35+
1936
/**
2037
* sanitizes input options
2138
*

0 commit comments

Comments
 (0)