换行或简化或逐行处理长负载数据而不出错。

huangapple go评论72阅读模式
英文:

line break or simplify or make long payload data line by line without error

问题

我有一个变量 payload,这里只显示了一部分。

payload := strings.NewReader("json=%7B%22rent_content_layout%22%3A%22Original%22%2C%22start_verylargetext_enabled%22%3Afalse%2C%22auto_large_mode")

有没有办法使用 Golang 将这一行的变量数据拆分成多行或者使其更易读?在 Bash 或者 Shell 中,我们可以使用 \n 进行换行,有没有类似的技巧可以在 Golang 中实现换行?

英文:

I had a variable payload, it is too long here just a part.

payload := strings.NewReader("json=%7B%22rent_content_layout%22%3A%22Original%22%2C%22start_verylargetext_enabled%22%3Afalse%2C%22auto_large_mode")

is any way to make the one line var data to multi line or make it human readable using golang, for bash or shell we use \n, is any trick to line break it using golang

答案1

得分: 1

只需使用+运算符进行字符串连接,并将字符串分解为小部分。

payload := strings.NewReader(
		"json=%7B%22" +
		"rent_content_layout%22%3A%22" +
		"Original%22%2C%22" +
		"start_verylargetext_enabled%22%3A" +
		"false%2C%22auto_large_mode")
英文:

Simply do the string concatenation with the + operator and break the string into small parts.

payload := strings.NewReader(
		"json=%7B%22" +
		"rent_content_layout%22%3A%22" +
		"Original%22%2C%22" +
		"start_verylargetext_enabled%22%3A" +
		"false%2C%22auto_large_mode")

huangapple
  • 本文由 发表于 2022年8月16日 01:20:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/73364370.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定