GoLand 2024.1 Help

Formatting strings

GoLand provides a feature that identifies Printf-like functions and applies corresponding coding assistance to them (for example, inspections, quick-fixes, spellchecking, highlighting, code folding, and so on).

A function is automatically recognized as Printf-like. The criteria for a function to be a candidate for Printf-like recognition are:

  • It is a function or method.

  • Its name ends with f (for example, Printf, Sprintf, Foof).

  • It contains at least two arguments.

  • The second-to-last argument is a string.

  • The last argument is variadic and of the empty interface type (interface{}).

On the following screenshot, Printf-like functions are highlighted in green color.

Candidates for printf-like recognition

You can exclude the function from the list of Printf-like functions if it was detected as formatting automatically. To exclude the function, use intention actions by pressing Alt+Enter or go to the settings.

Exclude formatting functions in the settings

  1. Press Ctrl+Alt+S to open settings and then select Go | Formatting functions.

  2. Click Add (the Add button).

  3. Start typing the name of the function or method that you want to exclude.

  4. Select a function or a method from the drop-down list.

  5. Press Enter.

    Adding formatting functions in settings

Exclude formatting functions in the editor

  • In the editor, click the function and press Alt+Enter, and select Exclude string formatting function.

    To edit functions and methods that were excluded from the list of formatting functions, open settings by pressing Ctrl+Alt+S and navigate to Go | Formatting strings. .

    Candidates for printf-like recognition
Last modified: 11 February 2024