-4

I am trying to break a string literal into multiple lines to meet my linter's expectations of short lines. Following is the code right now, it passes the linter check:

return nil,
    "",
    errors.Errorf(
            `nil cursor returned when querying for transactions for block hash %s, 
page token %s and limit %d`,
            blockHash,
            pageToken,
            limit,
    )

I don't like the formatting of the string literal. It feels aesthetically wrong ;). Is there a better way to format this? Thanks!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
septerr
  • 6,445
  • 9
  • 50
  • 73
  • Aside from the opinionated nature of the question, this is a duplicate of: https://stackoverflow.com/q/7933460/13860 – Jonathan Hall Aug 24 '21 at 07:43
  • Does this answer your question? [How do you write multiline strings in Go?](https://stackoverflow.com/questions/7933460/how-do-you-write-multiline-strings-in-go) – blackgreen Aug 24 '21 at 08:57

2 Answers2

1

Use string concatenation to construct the string from shorter lines:

errors.Errorf(
        `nil cursor returned when querying for transactions` +
        ` for block hash %s, page token %s and limit %d`,
        blockHash,
        pageToken,
        limit,
 )
1

You can use string addition:

errors.Errorf(`nil cursor returned when querying for `+
`transactions for block hash %s, page token %s and limit %d`,
            blockHash,
            pageToken,
            limit,
    )
Burak Serdar
  • 46,455
  • 3
  • 40
  • 59