5 "import \"${1:package}\""
7 "description": "import statement"
16 "description": "a import block"
21 "const ${1:name} = ${2:value}"
23 "description": "a constant"
25 "multiple constants": {
29 "\t${1:name} = ${2:value}",
32 "description": "a constant block"
34 "type function declaration": {
37 "type ${1:name} func($3) $4"
39 "description": "a type function declaration"
41 "type interface declaration": {
44 "type ${1:name} interface {",
48 "description": "a type interface"
50 "type struct declaration": {
53 "type ${1:name} struct {",
57 "description": "a struct declaration"
59 "package main and main function": {
68 "description": "main package & function"
70 "function declaration": {
77 "description": "function declaration"
79 "variable declaration": {
82 "var ${1:name} ${2:type}"
84 "description": "a variable"
89 "switch ${1:expression} {",
90 "case ${2:condition}:",
94 "description": "switch statement"
100 "case ${1:condition}:",
104 "description": "select statement"
109 "case ${1:condition}:$0"
111 "description": "case clause"
116 "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {",
120 "description": "a for loop"
122 "for range statement": {
125 "for ${1:_, }${2:v} := range ${3:v} {",
129 "description": "a for range loop"
131 "channel declaration": {
136 "description": "a channel"
141 "map[${1:type}]${2:type}"
143 "description": "a map"
150 "description": "empty interface"
155 "if ${1:condition} {",
159 "description": "if statement"
168 "description": "else branch"
170 "if else statement": {
173 "if ${1:condition} {",
179 "description": "if else"
185 "\t${1:return ${2:nil, }${3:err}}",
188 "description": "if err != nil"
193 "fmt.Println(\"$1\")"
195 "description": "fmt.Println()"
200 "fmt.Printf(\"$1\", ${2:var})"
202 "description": "fmt.Printf()"
207 "log.Println(\"$1\")"
209 "description": "log.Println()"
214 "log.Printf(\"$1\", ${2:var})"
216 "description": "log.Printf()"
218 "log variable content": {
221 "log.Printf(\"${1:var}: %#+v\\\\n\", ${1:var})"
223 "description": "log.Printf() with variable content"
230 "description": "t.Log()"
235 "t.Logf(\"$1\", ${2:var})"
237 "description": "t.Logf()"
239 "t.Logf variable content": {
242 "t.Logf(\"${1:var}: %#+v\\\\n\", ${1:var})"
244 "description": "t.Logf() with variable content"
249 "make(${1:type}, ${2:0})"
251 "description": "make statement"
258 "description": "new statement"
265 "description": "panic"
267 "http ResponseWriter *Request": {
270 "${1:w} http.ResponseWriter, ${2:r} *http.Request"
272 "description": "http Response"
277 "${1:http}.HandleFunc(\"${2:/}\", ${3:handler})"
279 "description": "http.HandleFunc()"
281 "http handler declaration": {
284 "func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request) {",
288 "description": "http handler declaration"
293 "http.Redirect(${1:w}, ${2:r}, \"${3:/}\", ${4:http.StatusFound})"
295 "description": "http.Redirect()"
300 "http.Error(${1:w}, ${2:err}.Error(), ${3:http.StatusInternalServerError})"
302 "description": "http.Error()"
304 "http.ListenAndServe": {
307 "http.ListenAndServe(\"${1::8080}\", ${2:nil})"
309 "description": "http.ListenAndServe"
314 "http.Serve(\"${1::8080}\", ${2:nil})"
316 "description": "http.Serve"
318 "goroutine anonymous function": {
325 "description": "anonymous goroutine declaration"
327 "goroutine function": {
332 "description": "goroutine declaration"
337 "defer ${1:func}($0)"
339 "description": "defer statement"
344 "func Test$1(t *testing.T) {",
348 "description": "Test function"
353 "func TestMain(m *testing.M) {",
356 "\tos.Exit(m.Run())",
359 "description": "TestMain function"
361 "benchmark function": {
364 "func Benchmark$1(b *testing.B) {",
365 "\tfor ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {",
370 "description": "Benchmark function"
372 "example function": {
375 "func Example$1() {",
381 "description": "Example function"
383 "table driven test": {
386 "func Test$1(t *testing.T) {",
387 "\ttestCases := []struct {",
392 "\t\t\tdesc: \"$3\",",
396 "\tfor _, tC := range testCases {",
397 "\t\tt.Run(tC.desc, func(t *testing.T) {",
403 "description": "table driven test"
412 "description": "init function"
421 "description": "main function"
423 "method declaration": {
426 "func (${1:receiver} ${2:type}) ${3:method}($4) $5 {",
430 "description": "method declaration"
432 "hello world web app": {
433 "prefix": "helloweb",
443 "func greet(w http.ResponseWriter, r *http.Request) {",
444 "\tfmt.Fprintf(w, \"Hello World! %s\", time.Now())",
448 "\thttp.HandleFunc(\"/\", greet)",
449 "\thttp.ListenAndServe(\":8080\", nil)",
452 "description": "sample hello world webapp"
454 "sort implementation": {
457 "type ${1:SortBy} []${2:Type}",
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]} }"
463 "description": "a custom sort.Sort interface implementation, for a given slice type."