2018-09-30 16:58:57 -04:00
|
|
|
snippet v "shorthand variable declaration"
|
2013-11-16 14:45:48 -05:00
|
|
|
${1} := ${2}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet vr "variable initialization"
|
2013-11-16 14:45:48 -05:00
|
|
|
var ${1:t} ${0:string}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet var "variable declaration"
|
2013-11-16 14:45:48 -05:00
|
|
|
var ${1} ${2} = ${3}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet vars "variables declaration"
|
2013-11-16 14:45:48 -05:00
|
|
|
var (
|
|
|
|
${1} ${2} = ${3}
|
|
|
|
)
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ap "append"
|
2013-11-16 14:45:48 -05:00
|
|
|
append(${1:slice}, ${0:value})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet bl "bool"
|
2012-08-16 23:41:25 -04:00
|
|
|
bool
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet bt "byte"
|
2012-08-16 23:41:25 -04:00
|
|
|
byte
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet br "break"
|
2012-08-16 23:41:25 -04:00
|
|
|
break
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ch "channel"
|
2013-11-16 14:45:48 -05:00
|
|
|
chan ${0:int}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet cs "case"
|
2012-08-16 23:41:25 -04:00
|
|
|
case ${1:value}:
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet co "constants with iota"
|
2012-08-16 23:41:25 -04:00
|
|
|
const (
|
|
|
|
${1:NAME1} = iota
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:NAME2}
|
2012-08-16 23:41:25 -04:00
|
|
|
)
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet cn "continue"
|
2012-08-16 23:41:25 -04:00
|
|
|
continue
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet df "defer"
|
2013-11-16 14:45:48 -05:00
|
|
|
defer ${0:func}()
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet dfr "defer recover"
|
2012-08-16 23:41:25 -04:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
|
|
|
}()
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet im "import"
|
2012-08-16 23:41:25 -04:00
|
|
|
import (
|
2013-07-17 19:06:05 -04:00
|
|
|
"${1:package}"
|
2013-11-16 14:45:48 -05:00
|
|
|
)
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet in "interface"
|
2012-08-16 23:41:25 -04:00
|
|
|
interface{}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet inf "full interface "
|
2012-08-16 23:41:25 -04:00
|
|
|
interface ${1:name} {
|
|
|
|
${2:/* methods */}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet if "if condition"
|
2022-09-25 06:10:28 -04:00
|
|
|
if ${1:/* condition */} {
|
2017-02-11 08:01:38 -05:00
|
|
|
${2:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
snippet ife "if else condition"
|
2022-09-25 06:10:28 -04:00
|
|
|
if ${1:/* condition */} {
|
2017-02-11 08:01:38 -05:00
|
|
|
${2:${VISUAL}}
|
2016-03-14 06:04:57 -04:00
|
|
|
} else {
|
|
|
|
${0}
|
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet el "else"
|
2012-08-16 23:41:25 -04:00
|
|
|
else {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ir "if error not nil, return err"
|
2012-08-16 23:41:25 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet f "false"
|
2012-08-16 23:41:25 -04:00
|
|
|
false
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ft "fallthrough"
|
2012-08-16 23:41:25 -04:00
|
|
|
fallthrough
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet fl "float"
|
2012-08-16 23:41:25 -04:00
|
|
|
float32
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet f3 "float32"
|
2012-08-16 23:41:25 -04:00
|
|
|
float32
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet f6 "float64"
|
2012-08-16 23:41:25 -04:00
|
|
|
float64
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet for "for loop"
|
2016-03-14 06:04:57 -04:00
|
|
|
for ${1}{
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2016-03-14 06:04:57 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet fori "for int loop"
|
2013-04-13 13:45:21 -04:00
|
|
|
for ${2:i} := 0; $2 < ${1:count}; $2${3:++} {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet forr "for range loop"
|
2016-03-14 06:04:57 -04:00
|
|
|
for ${1:e} := range ${2:collection} {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet fun "function"
|
2013-04-13 13:45:21 -04:00
|
|
|
func ${1:funcName}(${2}) ${3:error} {
|
2013-07-17 19:06:05 -04:00
|
|
|
${4}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet fum "method"
|
2015-01-18 07:58:28 -05:00
|
|
|
func (${1:receiver} ${2:type}) ${3:funcName}(${4}) ${5:error} {
|
|
|
|
${6}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
2020-12-04 16:15:32 -05:00
|
|
|
snippet fumh "http handler function on receiver"
|
2018-06-14 06:31:12 -04:00
|
|
|
func (${1:receiver} ${2:type}) ${3:funcName}(${4:w} http.ResponseWriter, ${5:r} *http.Request) {
|
|
|
|
${0:${VISUAL}}
|
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet lf "log printf"
|
2013-11-16 14:45:48 -05:00
|
|
|
log.Printf("%${1:s}", ${2:var})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet lp "log println"
|
2013-11-16 14:45:48 -05:00
|
|
|
log.Println("${1}")
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet mk "make"
|
2013-11-16 14:45:48 -05:00
|
|
|
make(${1:[]string}, ${0:0})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet mp "map"
|
2013-11-16 14:45:48 -05:00
|
|
|
map[${1:string}]${0:int}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet main "func main()"
|
2012-08-16 23:41:25 -04:00
|
|
|
func main() {
|
2013-07-17 19:06:05 -04:00
|
|
|
${1}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet nw "new"
|
2013-11-16 14:45:48 -05:00
|
|
|
new(${0:type})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet pa "package"
|
2015-01-18 07:58:28 -05:00
|
|
|
package ${1:main}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet pn "panic"
|
2013-11-16 14:45:48 -05:00
|
|
|
panic("${0:msg}")
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet pf "fmt.Printf()"
|
2013-11-16 14:45:48 -05:00
|
|
|
fmt.Printf("%${1:s}\n", ${2:var})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet pl "fmt.Println()"
|
2016-08-02 08:48:32 -04:00
|
|
|
fmt.Println("${1:s}")
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet rn "range"
|
2013-11-16 14:45:48 -05:00
|
|
|
range ${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet rt "return"
|
2013-11-16 14:45:48 -05:00
|
|
|
return ${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet rs "result"
|
2012-08-16 23:41:25 -04:00
|
|
|
result
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet sl "select"
|
2012-08-16 23:41:25 -04:00
|
|
|
select {
|
|
|
|
case ${1:v1} := <-${2:chan1}
|
2013-07-17 19:06:05 -04:00
|
|
|
${3}
|
2012-08-16 23:41:25 -04:00
|
|
|
default:
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet sr "string"
|
2012-08-16 23:41:25 -04:00
|
|
|
string
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet st "struct"
|
2012-08-16 23:41:25 -04:00
|
|
|
struct ${1:name} {
|
|
|
|
${2:/* data */}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet sw "switch"
|
2012-08-16 23:41:25 -04:00
|
|
|
switch ${1:var} {
|
|
|
|
case ${2:value1}:
|
2013-07-17 19:06:05 -04:00
|
|
|
${3}
|
2012-08-16 23:41:25 -04:00
|
|
|
case ${4:value2}:
|
2013-07-17 19:06:05 -04:00
|
|
|
${5}
|
2012-08-16 23:41:25 -04:00
|
|
|
default:
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ps "fmt.Sprintf"
|
2013-11-16 14:45:48 -05:00
|
|
|
fmt.Sprintf("%${1:s}", ${2:var})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet t "true"
|
2012-08-16 23:41:25 -04:00
|
|
|
true
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet g "goroutine named function"
|
2013-11-16 14:45:48 -05:00
|
|
|
go ${1:funcName}(${0})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ga "goroutine anonymous function"
|
2013-08-03 08:50:12 -04:00
|
|
|
go func(${1} ${2:type}) {
|
|
|
|
${3:/* code */}
|
2013-11-16 14:45:48 -05:00
|
|
|
}(${0})
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet test "test function"
|
2014-07-02 07:18:18 -04:00
|
|
|
func Test${1:name}(t *testing.T) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2014-07-02 07:18:18 -04:00
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
snippet testt "table test function"
|
|
|
|
func Test${1:name}(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "${2:test name}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
${0:${VISUAL}}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 16:58:57 -04:00
|
|
|
snippet bench "benchmark function"
|
2014-07-02 07:18:18 -04:00
|
|
|
func Benchmark${1:name}(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
${2}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${0}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet cl "composite literals"
|
2017-07-06 08:57:35 -04:00
|
|
|
type ${1:name} struct {
|
|
|
|
${2:attrName} ${3:attrType}
|
|
|
|
}
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet om "if key in a map"
|
2017-07-06 08:57:35 -04:00
|
|
|
if ${1:value}, ok := ${2:map}[${3:key}]; ok == true {
|
|
|
|
${4:/* code */}
|
|
|
|
}
|
|
|
|
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet gg "Grouped globals with anonymous struct"
|
2017-07-06 08:57:35 -04:00
|
|
|
var ${1:var} = struct{
|
|
|
|
${2:name} ${3:type}
|
|
|
|
}{
|
|
|
|
$2: ${4:value},
|
|
|
|
}
|
|
|
|
|
2018-09-30 16:58:57 -04:00
|
|
|
|
|
|
|
snippet ja "Marshalable json alias"
|
2017-07-06 08:57:35 -04:00
|
|
|
type ${1:parentType}Alias $1
|
|
|
|
|
|
|
|
func (p *$1) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&struct{ *$1Alias }{(*$1Alias)(p)})
|
|
|
|
}
|
2018-09-24 20:40:17 -04:00
|
|
|
|
2018-09-30 16:58:57 -04:00
|
|
|
|
2021-10-11 05:30:43 -04:00
|
|
|
snippet errwr "Error handling with fmt.Errorf"
|
2018-09-24 20:40:17 -04:00
|
|
|
if ${1}err != nil {
|
2021-10-11 05:30:43 -04:00
|
|
|
return fmt.Errorf("${2} %w", err)
|
2018-09-24 20:40:17 -04:00
|
|
|
}
|