What is the proposed style for indenting a raw string literal? If I indent it based on its first line, it might not align properly in editors that have a different tab length. For example:
if select == nil {
select, err = db.Prepare(`select name
from table
where id=$1`)
if err != nil {
return nil, err
}
}
I have found this question, but I am still unclear: Best practice for long string literals in Go
Should I do it like below?
if select == nil {
select, err = db.Prepare(`
select name
from table
where id=$1`)
if err != nil {
return nil, err
}
}
Considering both propositions would add newline or spaces to the litteral string, I would favor (even though fmt
format the first line):
select, err = db.Prepare(
`select name
from table
where id=$1`)
As the OP akonsu comments below, it seems consistent with the style of the golang code itself, as seen in src/cmd/go/main.go#L175
, which keeps the first line at the level of the opening '(
'
var usageTemplate = `Go is a tool for managing Go source code.
Usage:
go command [arguments]
...
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With