Home > Back-end >  How to "Evaluate and Log" a formatted string in Goland IDE breakpoint?
How to "Evaluate and Log" a formatted string in Goland IDE breakpoint?

Time:01-10

I'm using the "Evaluate and log" feature in Goland and can only print a string or a variable.

How can I log a string with a variable value embedded? I want something like "foo is now {fooVariableName}", but go doesn't have formatted strings.

CodePudding user response:

This IDE feature says "evaluate", which means you can put some expression there. So you can use something like this (if your variable is a string):

"foo is now "   fooVariableName

Or, if your variable is numeric

"foo is now "   strconv.Itoa(fooVariableName)

However it seems to be quite limited as you can only use already imported functions. So in example above you'll only be able to use strconv.Itoa if it's already used somewhere in your module.

P.S. I didn't know about this function, but tried and it looks useful, although a bit limited

  • Related