Extract method
Extract a function or a method
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.
Press Ctrl+Alt+M or on the main menu, select
.Type a method name and press Enter.
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