GoLand 2019.1 Help

Extract method

Extract a function or a method

  1. In the editor, select an expression or its part that you want to extract. You can also position the caret within the expression, in this case GoLand offers you a list of potential code selections.

  2. Press Ctrl+Alt+M or on the main menu, select Refactor | Extract | Extract Method.

  3. Type a method name and press Enter.

Example of the Extract a method refactoring

Code snippet

package main import "fmt" type rect struct { width, height int } func main() { r := rect{width: 10, height: 5} perim := 2*r.width + 2*r.height area := r.width * r.height fmt.Println("area: ", area) fmt.Println("perim:", perim) }
Last modified: 17 May 2019

See Also