Using the Generate action
Generate a constructor
The Generate constructor action generates a function that creates values of a struct type. For more information about constructors, see Constructors and composite literals from the Effective Go manual.
Place the caret at your code, and press Alt+Insert. Alternatively, you can use intention actions Alt+Enter.
In the Generate window, select Generate constructor.
In the Select Fields dialog, select fields that you want to use in the constructor.
Click OK.
Generate getter and setter
You can generate getters and setters separately or use one action to generate both methods. For more information about constructors, see Getters from the Effective Go manual.
Place the caret at your code, and press Alt+Insert. Alternatively, you can use intention actions Alt+Enter.
In the Generate window, select Getter and setter.
Implement missing methods
To implement an interface in Go, you need to implement all the methods that are listed in the interface. In GoLand, you can automatically generate templates for those methods.
With the Implement Methods action, you can specify parameter names even if they are omitted in the interface definition.
Place the caret at your code, and press Alt+Insert.
In the Generate window, select Implement Methods ( or press Ctrl+I).
In the Choose Type window, select the type that you want to use. Alternatively, click Create Type to create a new type.
In the Choose interface to implement field, type a name of the interface that you want to implement.
Replace the
panic("implement me")
line with a code for the method.
Generate an empty test file
Place the caret at your code, and press Alt+Insert.
In the Generate window, select Empty test file.
Generate tests for files, packages, and functions
Place the caret at your code, and press Alt+Insert.
In the Generate window, select Tests for file, Tests for package, or Test for function.
Generate a copyright
Press Ctrl+Alt+S to open the IDE settings and select
.Click the Add icon .
In the Create Copyright Profile dialog, type a name for a copyright profile.
In the Copyright text (may contain Velocity templates) field, create or modify a copyright template.
Click OK.
Place the caret at your code, and press Alt+Insert.
In the Generate window, select Copyright.