Skip to content

Instantly share code, notes, and snippets.

@telnet2
Last active February 14, 2022 15:41
Show Gist options
  • Save telnet2/3b501a816dc922d30c2ee8124c96f3cb to your computer and use it in GitHub Desktop.
Save telnet2/3b501a816dc922d30c2ee8124c96f3cb to your computer and use it in GitHub Desktop.
VSCode GO Gist (Library/Application Support/Code/User/snippets/go.json)
{
"context create": {
"prefix": "ctx",
"description": "create a background context",
"body": [
"ctx := context.${1:Background}()"
]
},
"anonymous defer function": {
"prefix": "dfc",
"description": "anonymous defer function",
"body": [
"defer func() {$1}()"
]
},
"TestMe function": {
"prefix": "tmf",
"description": "TestMe function",
"body": [
"func (tm *TestMe) Test$1() {",
"}",
""
]
},
"if ok": {
"prefix": "ifok",
"body": [
"if ${1:value}, ok := $2; ok {",
" $0",
"}"
]
},
"if error": {
"prefix": "rniferr",
"body": [
"if err := ${1}; err != nil {",
" $0",
"}",
"return nil"
]
},
"Return Nil": {
"prefix": "rn",
"body": [
"return nil"
]
},
"Return Nil & err": {
"prefix": "rne",
"body": [
"return nil, err"
]
},
"Return err": {
"prefix": "re",
"body": [
"return err"
]
},
"Struct": {
"prefix": "st",
"body": [
"type ${1:structName} struct {",
" $0",
"}"
]
},
"Struct Field": {
"prefix": "sf",
"body": [
"${1:fieldName} ${2:string}"
]
},
"Struct Tag": {
"prefix": "stt",
"body": [
"`${1:json}:\"${2:jsonFieldName}\"`"
]
},
"Interface": {
"prefix": "inte",
"body": [
"type ${1:interfaceName} interface {",
" $0",
"}"
]
},
"sync.Mutex Lock and defer Unlock": {
"prefix": "lock",
"body": [
"${1:mu}.Lock()",
"defer ${1:mu}.Unlock()"
]
},
"New Constructor Method": {
"prefix": "ne",
"body": [
"func New$1($2) *$1 {",
" $3",
" return &$1{",
" $0",
" }",
"}"
]
},
"For Range": {
"prefix": "fr",
"body": [
"for _, ${1:v} := range ${2:values} {",
" $0",
"}"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment