Skip to content

Instantly share code, notes, and snippets.

@wheelercj
Last active August 16, 2023 05:29
Show Gist options
  • Save wheelercj/bf587be7e1de4351c96f92929d840ce4 to your computer and use it in GitHub Desktop.
Save wheelercj/bf587be7e1de4351c96f92929d840ce4 to your computer and use it in GitHub Desktop.
VS Code snippet for Golang to return err if it's not nil. Just press alt+/ to insert the commonly used err-returning code.
{
"Return err if it's not nil": {
"prefix": "e?",
"body": [
"${TM_CURRENT_LINE/^(\\s*e\\?)|(\\s*if .+)|(\\s*)/${1:+if }${2:+ }${3:+if }/}err != nil {",
"\treturn${2} err",
"}",
]
}
}
[
{
"key": "alt+/",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"name": "Return err if it's not nil"
}
}
]
@wheelercj
Copy link
Author

demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment