Skip to content

Go: Use Multiline Strings for Raw Bodies#264

Merged
webholik merged 1 commit intopostmanlabs:developfrom
tooolbox:fix/golang-multiline
Oct 6, 2020
Merged

Go: Use Multiline Strings for Raw Bodies#264
webholik merged 1 commit intopostmanlabs:developfrom
tooolbox:fix/golang-multiline

Conversation

@tooolbox
Copy link
Contributor

This is random, but when looking up documentation for the CyberSource REST API I randomly came across these Postman docs. (How do such docs even come into being?...)

When I changed the language to Go - Native, what do I behold?

// ...
  payload := strings.NewReader("{
\n  	\"clientReferenceInformation\": {
\n  		\"code\": \"test_payment\"
\n  	},
\n  	\"processingInformation\": {
\n  		\"commerceIndicator\": \"internet\"
\n  	},						
\n  	\"orderInformation\": {
\n  		\"billTo\": {	
\n  			\"firstName\": \"John\",
\n  			\"lastName\": \"Doe\",
\n  			\"address1\": \"1 Market St\",
\n  			\"postalCode\": \"94105\",
\n  			\"locality\": \"san francisco\",
\n  			\"administrativeArea\": \"CA\",
\n  			\"country\": \"US\",
\n  			\"phoneNumber\": \"4158880000\",
\n  			\"company\": \"Visa\",
\n  			\"email\": \"test@cybs.com\"
\n  		},
\n  		\"amountDetails\": {
\n  			\"totalAmount\": \"102.21\",
\n  			\"currency\": \"USD\"
\n  		}
\n  	},
\n  	\"paymentInformation\": {
\n  		\"card\": {
\n  			\"expirationYear\": \"2031\",
\n  			\"number\": \"4111111111111111\",
\n  			\"securityCode\": \"123\",
\n  			\"expirationMonth\": \"12\"
\n  		}
\n  	}
\n  }")
// ...

Good heavens! This is why we have multiline literal strings in Go!

This PR should hopefully handle this travesty. Unfortunately my node-fu is not amazing, so even after an npm ci I couldn't actually get npm test to work without complaining about missing the newman module...so I gave up on that. I may not have all of my ducks in a row but this PR gets you most of the way there.

The new intended output is:

payload := strings.NewReader(`{
	"clientReferenceInformation": {
		"code": "test_payment"
	},
	"processingInformation": {
		"commerceIndicator": "internet"
	},						
	"orderInformation": {
		"billTo": {	
			"firstName": "John",
			"lastName": "Doe",
			"address1": "1 Market St",
			"postalCode": "94105",
			"locality": "san francisco",
			"administrativeArea": "CA",
			"country": "US",
			"phoneNumber": "4158880000",
			"company": "Visa",
			"email": "test@cybs.com"
		},
		"amountDetails": {
			"totalAmount": "102.21",
			"currency": "USD"
		}
	},
	"paymentInformation": {
		"card": {
			"expirationYear": "2031",
			"number": "4111111111111111",
			"securityCode": "123",
			"expirationMonth": "12"
		}
	}
`)

@webholik webholik merged commit cab17f7 into postmanlabs:develop Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants