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