Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Go Getters and Setters Generator NilsafeNew to Visual Studio Code? Get it now.
Go Getters and Setters Generator Nilsafe

Go Getters and Setters Generator Nilsafe

nxso

|
65 installs
| (1) | Free
Getter (incl. nilsafe variant) and Setter generator for Go stucts
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Go getters and setters generator nilsafe (ggsgornil)

A VSCode extension to automatically generate getters (standard + nilsafe methods) and setters for struct fields.

  • GetName() string
  • GetNameOrNil() *string => allows (panic free) optional chaining
  • SetName(name string) *Struct => allows method chaining

A fork of ggsg

  • Added support for nilsafe getters GetNameOrNil() *string => additional feature that allows (panic free) optional chaining
  • Added support for imported packages []*time.Time (bug fix)
  • Added support for []*Struct and []Struct fields (bug fix)

Features

This extension generates pointer receivers. Setters always return the struct pointer to allow method chaining.

How to use

  1. Select a struct and all of its fields
  2. Shift+CMD+P Select command & return

Usage

Note: The first line in your selection should always be a struct declaration. The extension will only generate getters and setters for selected fields.

Extension Settings

None at the moment

Known Issues

Nested structs are not yet supported. Workaround => create a separate type for the nested struct and use it as a field in the parent struct.

// not working
type Nested struct {
	a    *A
	nest struct {
		nest2 struct {
			nest3 struct {
				b *B
			}
		}
	}
}

// working
type Nested struct {
  a    *A
  nest *Nest2
}

type Nest2 struct {
  nest2 *Nest3
}

type Nest3 struct {
  b *B
}

Release Notes

1.0.5

  • Improved handling of any / interface{} types

1.0.4

  • Added support for map[string]interface{} types

1.0.3

  • Insert code below the struct declaration instead of EOF
  • // ## GENERATED - Getters & Setters for 'Invoice' ## comment added above generated code
  • // ## END GENERATED - Getters & Setters for 'Invoice' ## comment added below generated code

1.0.2

  • Added support for nilsafe getters GetNameOrNil() *string
  • Added support for imported packages []*time.Time
  • Added support for []*Struct and []Struct fields

1.0.0

Initial release of ggsgornil

Hope you enjoy this extension!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft