massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / snippets / go.json
1 {
2   "single import": {
3     "prefix": "im",
4     "body": [
5       "import \"${1:package}\""
6     ],
7     "description": "import statement"
8   },
9   "multiple imports": {
10     "prefix": "ims",
11     "body": [
12       "import (",
13       "\t\"${1:package}\"",
14       ")"
15     ],
16     "description": "a import block"
17   },
18   "single constant": {
19     "prefix": "co",
20     "body": [
21       "const ${1:name} = ${2:value}"
22     ],
23     "description": "a constant"
24   },
25   "multiple constants": {
26     "prefix": "cos",
27     "body": [
28       "const (",
29       "\t${1:name} = ${2:value}",
30       ")"
31     ],
32     "description": "a constant block"
33   },
34   "type function declaration": {
35     "prefix": "tyf",
36     "body": [
37       "type ${1:name} func($3) $4"
38     ],
39     "description": "a type function declaration"
40   },
41   "type interface declaration": {
42     "prefix": "tyi",
43     "body": [
44       "type ${1:name} interface {",
45       "\t$0",
46       "}"
47     ],
48     "description": "a type interface"
49   },
50   "type struct declaration": {
51     "prefix": "tys",
52     "body": [
53       "type ${1:name} struct {",
54       "\t$0",
55       "}"
56     ],
57     "description": "a struct declaration"
58   },
59   "package main and main function": {
60     "prefix": "pkgm",
61     "body": [
62       "package main",
63       "",
64       "func main() {",
65       "\t$0",
66       "}"
67     ],
68     "description": "main package & function"
69   },
70   "function declaration": {
71     "prefix": "func",
72     "body": [
73       "func $1($2) $3 {",
74       "\t$0",
75       "}"
76     ],
77     "description": "function declaration"
78   },
79   "variable declaration": {
80     "prefix": "var",
81     "body": [
82       "var ${1:name} ${2:type}"
83     ],
84     "description": "a variable"
85   },
86   "switch statement": {
87     "prefix": "switch",
88     "body": [
89       "switch ${1:expression} {",
90       "case ${2:condition}:",
91       "\t$0",
92       "}"
93     ],
94     "description": "switch statement"
95   },
96   "select statement": {
97     "prefix": "sel",
98     "body": [
99       "select {",
100       "case ${1:condition}:",
101       "\t$0",
102       "}"
103     ],
104     "description": "select statement"
105   },
106   "case clause": {
107     "prefix": "cs",
108     "body": [
109       "case ${1:condition}:$0"
110     ],
111     "description": "case clause"
112   },
113   "for statement": {
114     "prefix": "for",
115     "body": [
116       "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {",
117       "\t$0",
118       "}"
119     ],
120     "description": "a for loop"
121   },
122   "for range statement": {
123     "prefix": "forr",
124     "body": [
125       "for ${1:_, }${2:v} := range ${3:v} {",
126       "\t$0",
127       "}"
128     ],
129     "description": "a for range loop"
130   },
131   "channel declaration": {
132     "prefix": "ch",
133     "body": [
134       "chan ${1:type}"
135     ],
136     "description": "a channel"
137   },
138   "map declaration": {
139     "prefix": "map",
140     "body": [
141       "map[${1:type}]${2:type}"
142     ],
143     "description": "a map"
144   },
145   "empty interface": {
146     "prefix": "in",
147     "body": [
148       "interface{}"
149     ],
150     "description": "empty interface"
151   },
152   "if statement": {
153     "prefix": "if",
154     "body": [
155       "if ${1:condition} {",
156       "\t$0",
157       "}"
158     ],
159     "description": "if statement"
160   },
161   "else branch": {
162     "prefix": "el",
163     "body": [
164       "else {",
165       "\t$0",
166       "}"
167     ],
168     "description": "else branch"
169   },
170   "if else statement": {
171     "prefix": "ie",
172     "body": [
173       "if ${1:condition} {",
174       "\t$2",
175       "} else {",
176       "\t$0",
177       "}"
178     ],
179     "description": "if else"
180   },
181   "if err != nil": {
182     "prefix": "iferr",
183     "body": [
184       "if err != nil {",
185       "\t${1:return ${2:nil, }${3:err}}",
186       "}"
187     ],
188     "description": "if err != nil"
189   },
190   "fmt.Println": {
191     "prefix": "fp",
192     "body": [
193       "fmt.Println(\"$1\")"
194     ],
195     "description": "fmt.Println()"
196   },
197   "fmt.Printf": {
198     "prefix": "ff",
199     "body": [
200       "fmt.Printf(\"$1\", ${2:var})"
201     ],
202     "description": "fmt.Printf()"
203   },
204   "log.Println": {
205     "prefix": "lp",
206     "body": [
207       "log.Println(\"$1\")"
208     ],
209     "description": "log.Println()"
210   },
211   "log.Printf": {
212     "prefix": "lf",
213     "body": [
214       "log.Printf(\"$1\", ${2:var})"
215     ],
216     "description": "log.Printf()"
217   },
218   "log variable content": {
219     "prefix": "lv",
220     "body": [
221       "log.Printf(\"${1:var}: %#+v\\\\n\", ${1:var})"
222     ],
223     "description": "log.Printf() with variable content"
224   },
225   "t.Log": {
226     "prefix": "tl",
227     "body": [
228       "t.Log(\"$1\")"
229     ],
230     "description": "t.Log()"
231   },
232   "t.Logf": {
233     "prefix": "tlf",
234     "body": [
235       "t.Logf(\"$1\", ${2:var})"
236     ],
237     "description": "t.Logf()"
238   },
239   "t.Logf variable content": {
240     "prefix": "tlv",
241     "body": [
242       "t.Logf(\"${1:var}: %#+v\\\\n\", ${1:var})"
243     ],
244     "description": "t.Logf() with variable content"
245   },
246   "make(...)": {
247     "prefix": "make",
248     "body": [
249       "make(${1:type}, ${2:0})"
250     ],
251     "description": "make statement"
252   },
253   "new(...)": {
254     "prefix": "new",
255     "body": [
256       "new(${1:type})"
257     ],
258     "description": "new statement"
259   },
260   "panic(...)": {
261     "prefix": "pn",
262     "body": [
263       "panic(\"$0\")"
264     ],
265     "description": "panic"
266   },
267   "http ResponseWriter *Request": {
268     "prefix": "wr",
269     "body": [
270       "${1:w} http.ResponseWriter, ${2:r} *http.Request"
271     ],
272     "description": "http Response"
273   },
274   "http.HandleFunc": {
275     "prefix": "hf",
276     "body": [
277       "${1:http}.HandleFunc(\"${2:/}\", ${3:handler})"
278     ],
279     "description": "http.HandleFunc()"
280   },
281   "http handler declaration": {
282     "prefix": "hand",
283     "body": [
284       "func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request) {",
285       "\t$0",
286       "}"
287     ],
288     "description": "http handler declaration"
289   },
290   "http.Redirect": {
291     "prefix": "rd",
292     "body": [
293       "http.Redirect(${1:w}, ${2:r}, \"${3:/}\", ${4:http.StatusFound})"
294     ],
295     "description": "http.Redirect()"
296   },
297   "http.Error": {
298     "prefix": "herr",
299     "body": [
300       "http.Error(${1:w}, ${2:err}.Error(), ${3:http.StatusInternalServerError})"
301     ],
302     "description": "http.Error()"
303   },
304   "http.ListenAndServe": {
305     "prefix": "las",
306     "body": [
307       "http.ListenAndServe(\"${1::8080}\", ${2:nil})"
308     ],
309     "description": "http.ListenAndServe"
310   },
311   "http.Serve": {
312     "prefix": "sv",
313     "body": [
314       "http.Serve(\"${1::8080}\", ${2:nil})"
315     ],
316     "description": "http.Serve"
317   },
318   "goroutine anonymous function": {
319     "prefix": "go",
320     "body": [
321       "go func($1) {",
322       "\t$0",
323       "}($2)"
324     ],
325     "description": "anonymous goroutine declaration"
326   },
327   "goroutine function": {
328     "prefix": "gf",
329     "body": [
330       "go ${1:func}($0)"
331     ],
332     "description": "goroutine declaration"
333   },
334   "defer statement": {
335     "prefix": "df",
336     "body": [
337       "defer ${1:func}($0)"
338     ],
339     "description": "defer statement"
340   },
341   "test function": {
342     "prefix": "tf",
343     "body": [
344       "func Test$1(t *testing.T) {",
345       "\t$0",
346       "}"
347     ],
348     "description": "Test function"
349   },
350   "test main": {
351     "prefix": "tm",
352     "body": [
353       "func TestMain(m *testing.M) {",
354       "\t$1",
355       "",
356       "\tos.Exit(m.Run())",
357       "}"
358     ],
359     "description": "TestMain function"
360   },
361   "benchmark function": {
362     "prefix": "bf",
363     "body": [
364       "func Benchmark$1(b *testing.B) {",
365       "\tfor ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {",
366       "\t\t$0",
367       "\t}",
368       "}"
369     ],
370     "description": "Benchmark function"
371   },
372   "example function": {
373     "prefix": "ef",
374     "body": [
375       "func Example$1() {",
376       "\t$2",
377       "\t//Output:",
378       "\t$3",
379       "}"
380     ],
381     "description": "Example function"
382   },
383   "table driven test": {
384     "prefix": "tdt",
385     "body": [
386       "func Test$1(t *testing.T) {",
387       "\ttestCases := []struct {",
388       "\t\tdesc\tstring",
389       "\t\t$2",
390       "\t}{",
391       "\t\t{",
392       "\t\t\tdesc: \"$3\",",
393       "\t\t\t$4",
394       "\t\t},",
395       "\t}",
396       "\tfor _, tC := range testCases {",
397       "\t\tt.Run(tC.desc, func(t *testing.T) {",
398       "\t\t\t$0",
399       "\t\t})",
400       "\t}",
401       "}"
402     ],
403     "description": "table driven test"
404   },
405   "init function": {
406     "prefix": "finit",
407     "body": [
408       "func init() {",
409       "\t$1",
410       "}"
411     ],
412     "description": "init function"
413   },
414   "main function": {
415     "prefix": "fmain",
416     "body": [
417       "func main() {",
418       "\t$1",
419       "}"
420     ],
421     "description": "main function"
422   },
423   "method declaration": {
424     "prefix": "meth",
425     "body": [
426       "func (${1:receiver} ${2:type}) ${3:method}($4) $5 {",
427       "\t$0",
428       "}"
429     ],
430     "description": "method declaration"
431   },
432   "hello world web app": {
433     "prefix": "helloweb",
434     "body": [
435       "package main",
436       "",
437       "import (",
438       "\t\"fmt\"",
439       "\t\"net/http\"",
440       "\t\"time\"",
441       ")",
442       "",
443       "func greet(w http.ResponseWriter, r *http.Request) {",
444       "\tfmt.Fprintf(w, \"Hello World! %s\", time.Now())",
445       "}",
446       "",
447       "func main() {",
448       "\thttp.HandleFunc(\"/\", greet)",
449       "\thttp.ListenAndServe(\":8080\", nil)",
450       "}"
451     ],
452     "description": "sample hello world webapp"
453   },
454   "sort implementation": {
455     "prefix": "sort",
456     "body": [
457       "type ${1:SortBy} []${2:Type}",
458       "",
459       "func (a $1) Len() int           { return len(a) }",
460       "func (a $1) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }",
461       "func (a $1) Less(i, j int) bool { ${3:return a[i] < a[j]} }"
462     ],
463     "description": "a custom sort.Sort interface implementation, for a given slice type."
464   }
465 }