go-native.js (hoppscotch-2.0.0) | : | go-native.js (hoppscotch-2.1.0) | ||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
rawRequestBody, | rawRequestBody, | |||
contentType, | contentType, | |||
headers, | headers, | |||
}) => { | }) => { | |||
const requestString = [] | const requestString = [] | |||
let genHeaders = [] | let genHeaders = [] | |||
// initial request setup | // initial request setup | |||
const requestBody = rawInput ? rawParams : rawRequestBody | const requestBody = rawInput ? rawParams : rawRequestBody | |||
if (method === "GET") { | if (method === "GET") { | |||
requestString.push( | requestString.push( | |||
`req, err := http.NewRequest("${method}", "${url}${pathName}${queryStrin g}")\n` | `req, err := http.NewRequest("${method}", "${url}${pathName}?${queryStri ng}")\n` | |||
) | ) | |||
} | } | |||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) { | if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) { | |||
genHeaders.push(`req.Header.Set("Content-Type", "${contentType}")\n`) | genHeaders.push(`req.Header.Set("Content-Type", "${contentType}")\n`) | |||
if (isJSONContentType(contentType)) { | if (isJSONContentType(contentType)) { | |||
requestString.push(`var reqBody = []byte(\`${requestBody}\`)\n\n`) | requestString.push(`var reqBody = []byte(\`${requestBody}\`)\n\n`) | |||
requestString.push( | requestString.push( | |||
`req, err := http.NewRequest("${method}", "${url}${pathName}${queryStr ing}", bytes.NewBuffer(reqBody))\n` | `req, err := http.NewRequest("${method}", "${url}${pathName}?${querySt ring}", bytes.NewBuffer(reqBody))\n` | |||
) | ) | |||
} else if (contentType.includes("x-www-form-urlencoded")) { | } else if (contentType.includes("x-www-form-urlencoded")) { | |||
requestString.push( | requestString.push( | |||
`req, err := http.NewRequest("${method}", "${url}${pathName}${queryStr ing}", strings.NewReader("${requestBody}"))\n` | `req, err := http.NewRequest("${method}", "${url}${pathName}?${querySt ring}", strings.NewReader("${requestBody}"))\n` | |||
) | ) | |||
} | } | |||
} | } | |||
// headers | // headers | |||
// auth | // auth | |||
if (auth === "Basic Auth") { | if (auth === "Basic Auth") { | |||
const basic = `${httpUser}:${httpPassword}` | const basic = `${httpUser}:${httpPassword}` | |||
genHeaders.push( | genHeaders.push( | |||
`req.Header.Set("Authorization", "Basic ${window.btoa( | `req.Header.Set("Authorization", "Basic ${window.btoa( | |||
End of changes. 3 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added |