Break string for code redability

I want to create a custom error but it has a really long string.

var ErrWrongPatternVars = errors.New("ERROR: Provided values for src and / or dst flags are of wrong pattern: Accepted Values: /org/environment or in case of single app comparison: org/environment/app where source and destination app should be the same")

What is the go - idiomatic way of breaking the above string for code readability?

multiLineString := `line 1
    line 2
    line 3`

That’s not the same. I think they are asking for something like C "foo" "bar" syntax.

I dont know that syntax. Can you explain please? Also another way is using \n new line characters inside the string.

The user does not want to have a single string that spans multiple lines, they want to span a single line string over many lines of code, to make the code less wide.

In C, you can just close and open string literals, they will be concatenated at compiletime if there ir only whitespace inbetween. Such making "foo" "bar" equivalent to "foobar".


Ok :slight_smile:

I take the constant parts and make them variables. Then I add them to to the dynamic parts. I generally build up long messages over several lines, finally using a single variable in the NewError() function

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.