1
0
Fork 0
nix-config/modules/neovim/snippets/go.json

72 lines
2.3 KiB
JSON

{
"type function declaration": {
"prefix": "tyf",
"body": "type ${1:name} func($3) $4",
"description": "Snippet for a type function declaration"
},
"type interface declaration": {
"prefix": "tyi",
"body": "type ${1:name} interface {\n\t$0\n}",
"description": "Snippet for a type interface"
},
"type struct declaration": {
"prefix": "tys",
"body": "type ${1:name} struct {\n\t$0\n}",
"description": "Snippet for a struct declaration"
},
"package main and main function": {
"prefix": "pkgm",
"body": "package main\n\nfunc main() {\n\t$0\n}",
"description": "Snippet for main package & function"
},
"function declaration": {
"prefix": "func",
"body": "func $1($2) $3 {\n\t$0\n}",
"description": "Snippet for function declaration"
},
"if err != nil": {
"prefix": "ir",
"body": "if err != nil {\n\t${1:return ${2:nil, }${3:err}}\n}",
"description": "Snippet for if err != nil"
},
"http handler declaration": {
"prefix": "hand",
"body": "func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request) {\n\t$0\n}",
"description": "Snippet for http handler declaration"
},
"table driven test": {
"prefix": "tdt",
"body": "func Test$1(t *testing.T) {\n\ttestCases := []struct {\n\t\tdesc\tstring\n\t\t$2\n\t}{\n\t\t{\n\t\t\tdesc: \"$3\",\n\t\t\t$4\n\t\t},\n\t}\n\tfor _, tC := range testCases {\n\t\tt.Run(tC.desc, func(t *testing.T) {\n\t\t\t$0\n\t\t})\n\t}\n}",
"description": "Snippet for table driven test"
},
"json tag": {
"prefix": "json",
"body": "`json:\"$1\"`",
"description": "Snippet for struct json tag"
},
"for range statement": {
"prefix": "forr",
"body": "for ${1:_, }${2:v} := range ${3:v} {\n\t$0\n}",
"description": "Snippet for a for range loop"
},
"for statement": {
"prefix": "for",
"body": "for ${1}{\n\t$0\n}",
"description": "Snippet for a pure for loop"
},
"for n statement": {
"prefix": "fori",
"body": "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}",
"description": "Snippet for a for loop"
},
"map declaration": {
"prefix": "map",
"body": "map[${1:type}]${2:type}",
"description": "Snippet for a map"
},
"if err := func(); err != nil": {
"pref": "ief",
"body": "if err := $1; err != nil {\n\t${2:return}}"
}
}