JetBrains Fleet 1.44 Help

List of Go postfix completion templates

This table summarizes the postfix completion templates that you can use with your Go code.

Name

Description

Example. Before

Example. After

!

Negates the boolean expression.

func foo(b bool) { if b! {} }
func foo(b bool) { if !b {} }

&

Adds the & operator before the expression.

func foo() *string { s := "ok" return s& }
func foo() *string { s := "ok" return &s }

*

Creates a dereference expression.

func m() { ptr := new(int) i := ptr* }
func m() { ptr := new(int) i := *ptr }

aappend

Wraps the expression with the append() built-in function and assigns its result to the expression.

func m() { slice.aappend }
func m() { slice = append(slice, ) }

append

Wraps the expression with the append() built-in function.

func m() { slice.append }
func m() { append(slice, ) }

appendAssign

Wraps the expression with the append() built-in function and assigns its result to the expression.

func m() { slice.appendAssign }
func m() { slice = append(slice, ) }

as

Wraps the expression with the errors.As() function.

func f() { var err error err.as }
func f() { var err error errors.As(err) }

cap

Wraps the expression with the cap() built-in function.

func m() { array.cap }
func m() { cap(array) }

close

Wraps the expression with the close() built-in function.

func m() { channel.close }
func m() { close(channel) }

complex

Wraps the expression with the complex() built-in function.

func m() { number.complex }
func m() { complex(number, ) }

copy

Wraps the expression with the copy() built-in function.

func m() { array.copy }
func m() { copy(array, ) }

d

Creates a dereference expression.

func m() { ptr := new(int) i := ptr.d }
func m() { ptr := new(int) i := *ptr }

delete

Wraps the expression with the delete() built-in function.

func m() { mapVariable.delete }
func m() { delete(mapVariable, ) }

dereference

Creates a dereference expression.

func m() { ptr := new(int) i := ptr.dereference }
func m() { ptr := new(int) i := *ptr }

else

Turns the E expression into if !E {}.

func m(b bool) { b.else }
func m(b bool) { if !b { } }

for

Creates the range form of the for loop to iterate over a slice or an array.

func m(arr []byte) { arr.for }
func m(arr []byte) { for e := range arr { } }

forr

Creates the range form of the for loop with an index and a value to iterate over a slice or an array.

func m(arr []byte) { arr.forr }
func m(arr []byte) { for i, b := range arr { } }

if

Turns the E expression into if E {}.

func m(b bool) { b.if }
func m(b bool) { if b { } }

imag

Wraps the expression with the imag() built-in function.

func m() { number.imag }
func m() { imag(number) }

is

Wraps the expression with the errors.Is() function.

func f() { var err error err.is }
func f() { var err error errors.Is(err) }

len

Wraps the expression with the len() built-in function.

func m() { array.len }
func m() { len(array) }

nil

Wraps the expression with the if statement that checks whether the expression is nil.

func m(arg interface{}) { arg.nil }
func m(arg interface{}) { if arg == nil { } }

nil

Checks whether the if condition expression is nil.

func _() { if x := foo(); x.nil }
func _() { if x := foo(); x == nil { } }

nn

Wraps the expression with the if statement that checks whether the expression is not nil.

func m(arg interface{}) { arg.nn }
func m(arg interface{}) { if arg != nil { } }

nn

Checks whether the if condition expression is not nil.

func _() { if err := foo(); err.nn }
func _() { if err := foo(); err != nil { } }

not

Negates the boolean expression.

func foo(b bool) { if b.not {} }
func foo(b bool) { if !b {} }

notnil

Wraps the expression with the if statement that checks whether the expression is not nil.

func m(arg interface{}) { arg.notnil }
func m(arg interface{}) { if arg != nil { } }

notnil

Checks whether the if condition expression is not nil.

func _() { if err := foo(); err.notnil }
func _() { if err := foo(); err != nil { } }

p

Adds the & operator before the expression.

func foo() *string { s := "ok" return s.p }
func foo() *string { s := "ok" return &s }

panic

Wraps the expression with the panic() built-in function.

func m() { "expression".panic }
func m() { panic("expression") }

par

Wraps the expression with parentheses.

func m(arg interface{}) { arg.par }
func m(arg interface{}) { (arg) }

parseFloat

Generates the code to parse float64 from string.

func foo() { "12.34".parseFloat }
func foo() { value, err := strconv.ParseFloat("123", 64) }

parseInt

Generates the code to parse int from string.

func foo() { "123".parseInt }
func foo() { value, err := strconv.ParseInt("123", 10, 64) }

pointer

Adds the & operator before the expression.

func foo() *string { s := "ok" return s.pointer }
func foo() *string { s := "ok" return &s }

print

Wraps the expression with the print() built-in function.

func m() { "expression".print }
func m() { print("expression") }

println

Wraps the expression with the println() built-in function.

func m() { "expression".println }
func m() { println("expression") }

real

Wraps the expression with the real() built-in function.

func m() { number.real }
func m() { real(number) }

remove

Creates a copy of a slice with a range of elements removed. For more information about operations with slices, see Slice Tricks in the golang repository at github.com.

func m() { slice.remove }
func m() { slice = append(slice[:1], slice[2:]...) }

reterr

Generates boilerplate code for idiomatic error handling. Can be called on variables and expressions of the error type. Replaces the err variable with the following construction: if err != nil { return value1, value2, ... } Replaces the expr expression with the following construction: if err := expr; err != nil { return value1, value2, ... } Each value is either the err variable or a default value of the corresponding return type of the enclosing function. You can call this template on expressions with multiple values.

func read(file string) (int, error) { f, err := os.Open(file) err.reterr } func read(file *os.File, data []byte) (int, error) { file.Write(data).reterr }
func read(file string) (int, error) { f, err := os.Open(file) if err != nil { return 0, err } } func read(file *os.File, data []byte) (int, error) { if _, err := file.Write(data); err != nil { return 0, err } }

return

Adds the return keyword before the expression.

func m() { "result".return }
func m() { return "result" }

rr

Generates boilerplate code for idiomatic error handling. Can be called on variables and expressions of the error type. Replaces variable err with the following construction: if err != nil { return value1, value2, ... } Replaces expression expr with the following construction: if err := expr; err != nil { return value1, value2, ... } Each value is either the err variable or a default value of the corresponding return type of the enclosing function. You can call this template on expressions with multiple values.

func read(file string) (int, error) { f, err := os.Open(file) err.rr } func read(file *os.File, data []byte) (int, error) { file.Write(data).rr }
func read(file string) (int, error) { f, err := os.Open(file) if err != nil { return 0, err } } func read(file *os.File, data []byte) (int, error) { if _, err := file.Write(data); err != nil { return 0, err } }

sort

Wraps the expression with the sort.Float64s() function.

func foo() { data := []float64{} data.sort }
func foo() { data := []float64{} sort.Float64s(data) }

sort

Wraps the expression with the sort.Ints() function.

func foo() { data := []int{} data.sort }
func foo() { data := []int{} sort.Ints(data) }

sort

Wraps the expression with the sort.Slice() function.

func foo() { data := []struct{a string}{} data.sort }
func foo() { data := []struct{a string}{} sort.Slice(data, func(i, j int) bool { return false }) }

sort

Wraps the expression with the sort.Sort() function.

package foo func _() { people := []Person{} ByAge(people).sort } type Person struct { Name string Age int } // ByAge implements sort.Interface for []Person based on // the Age field. type ByAge []Person func (a ByAge) Len() int { return len(a) } func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age }
package foo func _() { people := []Person{} sort.Sort(ByAge(people)) } type Person struct { Name string Age int } // ByAge implements sort.Interface for []Person based on // the Age field. type ByAge []Person func (a ByAge) Len() int { return len(a) } func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age }

sort

Wraps the expression with the sort.Strings() function.

func foo() { data := []string{} data.sort }
func foo() { data := []string{} sort.Strings(data) }

var

Assigns the expression to a new variable by using :=.

func m(arg interface{}) { arg.var }
func m(arg interface{}) { i := arg }

varCheckError

Generates boilerplate code for idiomatic error handling. You can invoke the template on calls that return error or on any expressions of the error type. The template introduces new variables, assigns the expression to them, and checks if error is not nil by using the following code: if err != nil { return value1, value2, ... } Each value is either the err variable or a default value of the corresponding return type of the enclosing function.

func read(file string) (int, error) { os.Open(file).varCheckError }
func read(file string) (int, error) { f, err := os.Open(file) if err != nil { return 0, err } }
Last modified: 11 February 2024