2013-11-16 14:45:48 -05:00
|
|
|
# shorthand variable declaration
|
|
|
|
snippet v
|
|
|
|
${1} := ${2}
|
|
|
|
# variable initialization
|
|
|
|
snippet vr
|
|
|
|
var ${1:t} ${0:string}
|
|
|
|
# variable declaration
|
|
|
|
snippet var
|
|
|
|
var ${1} ${2} = ${3}
|
|
|
|
# variables declaration
|
|
|
|
snippet vars
|
|
|
|
var (
|
|
|
|
${1} ${2} = ${3}
|
|
|
|
)
|
2012-08-16 23:41:25 -04:00
|
|
|
# append
|
|
|
|
snippet ap
|
2013-11-16 14:45:48 -05:00
|
|
|
append(${1:slice}, ${0:value})
|
2012-08-16 23:41:25 -04:00
|
|
|
# bool
|
|
|
|
snippet bl
|
|
|
|
bool
|
2013-07-17 19:06:05 -04:00
|
|
|
# byte
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet bt
|
|
|
|
byte
|
|
|
|
# break
|
|
|
|
snippet br
|
|
|
|
break
|
|
|
|
# channel
|
|
|
|
snippet ch
|
2013-11-16 14:45:48 -05:00
|
|
|
chan ${0:int}
|
2012-08-16 23:41:25 -04:00
|
|
|
# case
|
|
|
|
snippet cs
|
|
|
|
case ${1:value}:
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
# const
|
|
|
|
snippet c
|
2013-11-16 14:45:48 -05:00
|
|
|
const ${1:NAME} = ${0:0}
|
2012-08-16 23:41:25 -04:00
|
|
|
# constants with iota
|
|
|
|
snippet co
|
|
|
|
const (
|
|
|
|
${1:NAME1} = iota
|
2013-11-16 14:45:48 -05:00
|
|
|
${0:NAME2}
|
2012-08-16 23:41:25 -04:00
|
|
|
)
|
|
|
|
# continue
|
|
|
|
snippet cn
|
|
|
|
continue
|
2013-07-17 19:06:05 -04:00
|
|
|
# defer
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet df
|
2013-11-16 14:45:48 -05:00
|
|
|
defer ${0:func}()
|
2012-08-16 23:41:25 -04:00
|
|
|
# defer recover
|
|
|
|
snippet dfr
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
# int
|
|
|
|
snippet i
|
|
|
|
int
|
2013-07-17 19:06:05 -04:00
|
|
|
# import
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet im
|
|
|
|
import (
|
2013-07-17 19:06:05 -04:00
|
|
|
"${1:package}"
|
2013-11-16 14:45:48 -05:00
|
|
|
)
|
2013-07-17 19:06:05 -04:00
|
|
|
# interface
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet in
|
|
|
|
interface{}
|
2013-07-17 19:06:05 -04:00
|
|
|
# full interface snippet
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet inf
|
|
|
|
interface ${1:name} {
|
|
|
|
${2:/* methods */}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2012-08-16 23:41:25 -04:00
|
|
|
# if condition
|
|
|
|
snippet if
|
|
|
|
if ${1:/* condition */} {
|
2017-08-03 11:21:37 -04:00
|
|
|
${2:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2016-03-14 06:04:57 -04:00
|
|
|
snippet ife
|
|
|
|
if ${1:/* condition */} {
|
2017-08-03 11:21:37 -04:00
|
|
|
${2:${VISUAL}}
|
2016-03-14 06:04:57 -04:00
|
|
|
} else {
|
|
|
|
${0}
|
|
|
|
}
|
2012-08-16 23:41:25 -04:00
|
|
|
# else snippet
|
|
|
|
snippet el
|
|
|
|
else {
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2012-08-16 23:41:25 -04:00
|
|
|
# error snippet
|
|
|
|
snippet ir
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
# false
|
|
|
|
snippet f
|
|
|
|
false
|
|
|
|
# fallthrough
|
|
|
|
snippet ft
|
|
|
|
fallthrough
|
|
|
|
# float
|
|
|
|
snippet fl
|
|
|
|
float32
|
|
|
|
# float32
|
|
|
|
snippet f3
|
|
|
|
float32
|
|
|
|
# float64
|
|
|
|
snippet f6
|
|
|
|
float64
|
2016-03-14 06:04:57 -04:00
|
|
|
# for int loop
|
|
|
|
snippet for
|
|
|
|
for ${1}{
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2016-03-14 06:04:57 -04:00
|
|
|
}
|
|
|
|
# for int loop
|
|
|
|
snippet fori
|
2013-04-13 13:45:21 -04:00
|
|
|
for ${2:i} := 0; $2 < ${1:count}; $2${3:++} {
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
|
|
|
# for range loop
|
2016-03-14 06:04:57 -04:00
|
|
|
snippet forr
|
|
|
|
for ${1:e} := range ${2:collection} {
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
}
|
2013-07-17 19:06:05 -04:00
|
|
|
# function simple
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet fun
|
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}
|
2013-07-17 19:06:05 -04:00
|
|
|
# function on receiver
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet fum
|
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}
|
2013-04-13 13:45:21 -04:00
|
|
|
# log printf
|
|
|
|
snippet lf
|
2013-11-16 14:45:48 -05:00
|
|
|
log.Printf("%${1:s}", ${2:var})
|
2013-04-13 13:45:21 -04:00
|
|
|
# log printf
|
|
|
|
snippet lp
|
2013-11-16 14:45:48 -05:00
|
|
|
log.Println("${1}")
|
2012-08-16 23:41:25 -04:00
|
|
|
# make
|
|
|
|
snippet mk
|
2013-11-16 14:45:48 -05:00
|
|
|
make(${1:[]string}, ${0:0})
|
2013-07-17 19:06:05 -04:00
|
|
|
# map
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet mp
|
2013-11-16 14:45:48 -05:00
|
|
|
map[${1:string}]${0:int}
|
2012-08-16 23:41:25 -04:00
|
|
|
# main()
|
|
|
|
snippet main
|
|
|
|
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}
|
2012-08-16 23:41:25 -04:00
|
|
|
# new
|
|
|
|
snippet nw
|
2013-11-16 14:45:48 -05:00
|
|
|
new(${0:type})
|
2015-01-18 07:58:28 -05:00
|
|
|
# package
|
|
|
|
snippet pa
|
|
|
|
package ${1:main}
|
2013-07-17 19:06:05 -04:00
|
|
|
# panic
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet pn
|
2013-11-16 14:45:48 -05:00
|
|
|
panic("${0:msg}")
|
2012-08-16 23:41:25 -04:00
|
|
|
# print
|
|
|
|
snippet pr
|
2013-11-16 14:45:48 -05:00
|
|
|
fmt.Printf("%${1:s}\n", ${2:var})
|
2016-08-02 08:48:32 -04:00
|
|
|
# println
|
|
|
|
snippet pl
|
|
|
|
fmt.Println("${1:s}")
|
2013-07-17 19:06:05 -04:00
|
|
|
# range
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet rn
|
2013-11-16 14:45:48 -05:00
|
|
|
range ${0}
|
2013-07-17 19:06:05 -04:00
|
|
|
# return
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet rt
|
2013-11-16 14:45:48 -05:00
|
|
|
return ${0}
|
2013-07-17 19:06:05 -04:00
|
|
|
# result
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet rs
|
|
|
|
result
|
|
|
|
# select
|
|
|
|
snippet sl
|
|
|
|
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
|
|
|
}
|
|
|
|
# string
|
|
|
|
snippet sr
|
|
|
|
string
|
|
|
|
# struct
|
|
|
|
snippet st
|
|
|
|
struct ${1:name} {
|
|
|
|
${2:/* data */}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-07-17 19:06:05 -04:00
|
|
|
# switch
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet sw
|
|
|
|
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
|
|
|
}
|
|
|
|
snippet sp
|
2013-11-16 14:45:48 -05:00
|
|
|
fmt.Sprintf("%${1:s}", ${2:var})
|
2013-07-17 19:06:05 -04:00
|
|
|
# true
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet t
|
|
|
|
true
|
2013-08-03 08:50:12 -04:00
|
|
|
# goroutine named function
|
|
|
|
snippet g
|
2013-11-16 14:45:48 -05:00
|
|
|
go ${1:funcName}(${0})
|
2016-03-14 06:04:57 -04:00
|
|
|
# goroutine anonymous function
|
2013-08-03 08:50:12 -04:00
|
|
|
snippet ga
|
|
|
|
go func(${1} ${2:type}) {
|
|
|
|
${3:/* code */}
|
2013-11-16 14:45:48 -05:00
|
|
|
}(${0})
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet test test function
|
|
|
|
func Test${1:name}(t *testing.T) {
|
2017-08-03 11:21:37 -04:00
|
|
|
${0:${VISUAL}}
|
2014-07-02 07:18:18 -04:00
|
|
|
}
|
|
|
|
snippet bench benchmark function
|
|
|
|
func Benchmark${1:name}(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
${2}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${0}
|
2017-08-03 11:21:37 -04:00
|
|
|
# composite literals
|
|
|
|
snippet cl
|
|
|
|
type ${1:name} struct {
|
|
|
|
${2:attrName} ${3:attrType}
|
|
|
|
}
|
|
|
|
# if key in a map
|
|
|
|
snippet om
|
|
|
|
if ${1:value}, ok := ${2:map}[${3:key}]; ok == true {
|
|
|
|
${4:/* code */}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Grouped globals with anonymous struct
|
|
|
|
snippet gg
|
|
|
|
var ${1:var} = struct{
|
|
|
|
${2:name} ${3:type}
|
|
|
|
}{
|
|
|
|
$2: ${4:value},
|
|
|
|
}
|
|
|
|
|
|
|
|
# Marshalable json alias
|
|
|
|
snippet ja
|
|
|
|
type ${1:parentType}Alias $1
|
|
|
|
|
|
|
|
func (p *$1) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&struct{ *$1Alias }{(*$1Alias)(p)})
|
|
|
|
}
|