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 interface declaration": {
37 "type ${1:name} interface {",
41 "description": "a type interface"
43 "type struct declaration": {
46 "type ${1:name} struct {",
50 "description": "a struct declaration"
52 "package main and main function": {
61 "description": "main package & function"
63 "function declaration": {
70 "description": "function declaration"
72 "variable declaration": {
75 "var ${1:name} ${2:type}"
77 "description": "a variable"
82 "switch ${1:expression} {",
83 "case ${2:condition}:",
87 "description": "switch statement"
93 "case ${1:condition}:",
97 "description": "select statement"
102 "case ${1:condition}:$0"
104 "description": "case clause"
109 "for ${1:i} := 0; $1 < ${2:count}; $1${3:++} {",
113 "description": "a for loop"
115 "for range statement": {
118 "for ${1:_, }${2:var} := range ${3:var} {",
122 "description": "a for range loop"
124 "channel declaration": {
129 "description": "a channel"
134 "map[${1:type}]${2:type}"
136 "description": "a map"
143 "description": "empty interface"
148 "if ${1:condition} {",
152 "description": "if statement"
161 "description": "else branch"
163 "if else statement": {
166 "if ${1:condition} {",
172 "description": "if else"
178 "\t${1:return ${2:nil, }${3:err}}",
181 "description": "if err != nil"
186 "fmt.Println(\"$1\")"
188 "description": "fmt.Println()"
193 "fmt.Printf(\"$1\", ${2:var})"
195 "description": "fmt.Printf()"
200 "log.Println(\"$1\")"
202 "description": "log.Println()"
207 "log.Printf(\"$1\", ${2:var})"
209 "description": "log.Printf()"
211 "log variable content": {
214 "log.Printf(\"${1:var}: %#+v\\\\n\", ${1:var})"
216 "description": "log.Printf() with variable content"
223 "description": "t.Log()"
228 "t.Logf(\"$1\", ${2:var})"
230 "description": "t.Logf()"
232 "t.Logf variable content": {
235 "t.Logf(\"${1:var}: %#+v\\\\n\", ${1:var})"
237 "description": "t.Logf() with variable content"
242 "make(${1:type}, ${2:0})"
244 "description": "make statement"
251 "description": "new statement"
258 "description": "panic"
260 "http ResponseWriter *Request": {
263 "${1:w} http.ResponseWriter, ${2:r} *http.Request"
265 "description": "http Response"
270 "${1:http}.HandleFunc(\"${2:/}\", ${3:handler})"
272 "description": "http.HandleFunc()"
274 "http handler declaration": {
277 "func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request) {",
281 "description": "http handler declaration"
286 "http.Redirect(${1:w}, ${2:r}, \"${3:/}\", ${4:http.StatusFound})"
288 "description": "http.Redirect()"
293 "http.Error(${1:w}, ${2:err}.Error(), ${3:http.StatusInternalServerError})"
295 "description": "http.Error()"
297 "http.ListenAndServe": {
300 "http.ListenAndServe(\"${1::8080}\", ${2:nil})"
302 "description": "http.ListenAndServe"
307 "http.Serve(\"${1::8080}\", ${2:nil})"
309 "description": "http.Serve"
311 "goroutine anonymous function": {
318 "description": "anonymous goroutine declaration"
320 "goroutine function": {
325 "description": "goroutine declaration"
330 "defer ${1:func}($0)"
332 "description": "defer statement"
337 "func Test$1(t *testing.T) {",
341 "description": "Test function"
343 "benchmark function": {
346 "func Benchmark$1(b *testing.B) {",
347 "\tfor ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {",
352 "description": "Benchmark function"
354 "example function": {
357 "func Example$1() {",
363 "description": "Example function"
365 "table driven test": {
368 "func Test$1(t *testing.T) {",
369 "\ttestCases := []struct {",
374 "\t\t\tdesc: \"$3\",",
378 "\tfor _, tC := range testCases {",
379 "\t\tt.Run(tC.desc, func(t *testing.T) {",
385 "description": "table driven test"
394 "description": "init function"
403 "description": "main function"
405 "method declaration": {
408 "func (${1:receiver} ${2:type}) ${3:method}($4) $5 {",
412 "description": "method declaration"
414 "hello world web app": {
415 "prefix": "helloweb",
425 "func greet(w http.ResponseWriter, r *http.Request) {",
426 "\tfmt.Fprintf(w, \"Hello World! %s\", time.Now())",
430 "\thttp.HandleFunc(\"/\", greet)",
431 "\thttp.ListenAndServe(\":8080\", nil)",
434 "description": "sample hello world webapp"
436 "sort implementation": {
439 "type ${1:SortBy} []${2:Type}",
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]} }"
445 "description": "a custom sort.Sort interface implementation, for a given slice type."