Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active April 24, 2023 11:31
Show Gist options
  • Save joseluisq/de9249a8aecfb7df2174f9814cbe9a5f to your computer and use it in GitHub Desktop.
Save joseluisq/de9249a8aecfb7df2174f9814cbe9a5f to your computer and use it in GitHub Desktop.
{
// Place your snippets for go here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"printf block": {
"prefix": "pr",
"body": [
"fmt.Printf(\"$1: %#v\\n\", $2)",
],
"description": "Snippet for printf"
},
"func declaration": {
"prefix": "fu",
"body": [
"func $1($2) $3 {",
"\t$4",
"}",
],
"description": "Snippet for function"
},
"return block": {
"prefix": "re",
"body": [
"return $1",
],
"description": "Snippet for return"
},
"if block": {
"prefix": "if",
"body": [
"if $1 {",
"\t$2",
"}",
],
"description": "Snippet for if err != nil"
},
"return if error block": {
"prefix": "er",
"body": [
"if err != nil {",
"\treturn ${1:nil, }${2:err}",
"}",
],
"description": "Snippet for if err != nil"
},
"single constant": {
"prefix": "co",
"body": "const ${1:name} = ${2:value}",
"description": "Snippet for a constant"
},
"main func declaration": {
"prefix": "ma",
"body": [
"func main() {",
"\t$1",
"}"
],
"description": "Snippet for main function"
},
"method declaration": {
"prefix": "me",
"body": [
"func (${1:receiver} *${2:type}) ${3:method}($4) $5 {",
"\t$0",
"}"
],
"description": "Snippet for method declaration"
},
"type struct declaration": {
"prefix": "ts",
"body": [
"type ${1:name} struct {",
"\t${2:prop} ${3:type}",
"}",
],
"description": "Snippet for struct declaration"
},
"type function declaration": {
"prefix": "tf",
"body": "type ${1:name} func($2) $3",
"description": "Snippet for type function declaration"
},
"type interface declaration": {
"prefix": "ti",
"body": [
"type ${1:name} interface {",
"\t$0",
"}"
],
"description": "Snippet for type interface"
},
"single variable": {
"prefix": "var",
"body": "var ${1:name} ${2:type}",
"description": "Snippet for a variable declaration"
},
"variable assignment": {
"prefix": "as",
"body": "${1:name} := ${2:value}",
"description": "Snippet for a variable assignment"
},
"switch statement": {
"prefix": "switch",
"body": "switch ${1:expression} {\ncase ${2:condition}:\n\t$0\n}",
"description": "Snippet for switch statement"
},
"for statement": {
"prefix": "for",
"body": "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}",
"description": "Snippet for a for loop"
},
"for range statement": {
"prefix": "forr",
"body": "for ${1:_, }${2:v} := range ${3:v} {\n\t$0\n}",
"description": "Snippet for a for range loop"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment