2014-10-31 17:30:24 -04:00
|
|
|
# shorthand variable declaration
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet :
|
|
|
|
abbr v := value
|
|
|
|
${1} := ${0}
|
|
|
|
# anonymous function
|
|
|
|
snippet anon
|
|
|
|
abbr fn := func() { ... }
|
|
|
|
${1:fn} := func() {
|
|
|
|
${0}
|
|
|
|
}
|
2014-10-31 17:30:24 -04:00
|
|
|
# append
|
|
|
|
snippet ap
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr append(slice, value)
|
2014-10-31 17:30:24 -04:00
|
|
|
append(${1:slice}, ${0:value})
|
2015-02-24 05:45:22 -05:00
|
|
|
# append assign
|
|
|
|
snippet ap=
|
|
|
|
abbr slice = append(slice, value)
|
|
|
|
${1:slice} = append($1, ${0:value})
|
2014-10-31 17:30:24 -04:00
|
|
|
# break
|
|
|
|
snippet br
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr break
|
2014-10-31 17:30:24 -04:00
|
|
|
break
|
|
|
|
# channel
|
|
|
|
snippet ch
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr chan Type
|
2014-10-31 17:30:24 -04:00
|
|
|
chan ${0:int}
|
|
|
|
# case
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet case
|
|
|
|
abbr case ...:
|
2014-10-31 17:30:24 -04:00
|
|
|
case ${1:value}:
|
|
|
|
${0}
|
2015-01-18 07:58:28 -05:00
|
|
|
# constant
|
|
|
|
snippet con
|
|
|
|
abbr const XXX Type = ...
|
|
|
|
const ${1:NAME} ${2:Type} = ${0:0}
|
|
|
|
# constants
|
|
|
|
snippet cons
|
|
|
|
abbr const ( ... )
|
|
|
|
const (
|
|
|
|
${1:NAME} ${2:Type} = ${3:value}
|
|
|
|
${0}
|
|
|
|
)
|
2014-10-31 17:30:24 -04:00
|
|
|
# constants with iota
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet iota
|
|
|
|
abbr const ( ... = iota )
|
2014-10-31 17:30:24 -04:00
|
|
|
const (
|
2015-01-18 07:58:28 -05:00
|
|
|
${1:NAME} ${2:Type} = iota
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
)
|
|
|
|
# continue
|
|
|
|
snippet cn
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr continue
|
2014-10-31 17:30:24 -04:00
|
|
|
continue
|
2015-01-18 07:58:28 -05:00
|
|
|
# default case
|
|
|
|
snippet default
|
|
|
|
abbr default: ...
|
|
|
|
default:
|
|
|
|
${0}
|
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
# defer
|
|
|
|
snippet df
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr defer someFunction()
|
|
|
|
defer ${1:func}(${2})
|
|
|
|
${0}
|
|
|
|
snippet def
|
|
|
|
abbr defer func() { ... }
|
|
|
|
defer func() {
|
|
|
|
${0}
|
|
|
|
}()
|
2014-10-31 17:30:24 -04:00
|
|
|
# defer recover
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet defr
|
2014-10-31 17:30:24 -04:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
# gpl
|
|
|
|
snippet gpl
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Copyright (C) ${1:Author}, `strftime("%Y")`
|
|
|
|
*/
|
|
|
|
|
|
|
|
${0}
|
|
|
|
# import
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet import
|
|
|
|
abbr import ( ... )
|
2014-10-31 17:30:24 -04:00
|
|
|
import (
|
|
|
|
"${1:package}"
|
|
|
|
)
|
|
|
|
# full interface snippet
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet interface
|
|
|
|
abbr interface I { ... }
|
|
|
|
type ${1:Interface} interface {
|
|
|
|
${2:/* TODO: add methods */}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
|
|
|
# if condition
|
|
|
|
snippet if
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr if ... { ... }
|
|
|
|
if ${1:condition} {
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
|
|
|
# else snippet
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr else { ... }
|
|
|
|
snippet else
|
2014-10-31 17:30:24 -04:00
|
|
|
else {
|
2015-01-18 07:58:28 -05:00
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2017-05-26 05:30:32 -04:00
|
|
|
|
|
|
|
# if inline error
|
|
|
|
snippet ife
|
|
|
|
abbr if err := ...; err != nil { ... }
|
|
|
|
if err := ${1:condition}; err != nil {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
# error snippet
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet errn
|
2018-02-04 06:35:08 -05:00
|
|
|
abbr if err != nil { return err }
|
2014-10-31 17:30:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-20 08:13:10 -05:00
|
|
|
${0}
|
2015-02-24 05:45:22 -05:00
|
|
|
# error snippet in TestFunc
|
|
|
|
snippet errt
|
2018-02-04 06:35:08 -05:00
|
|
|
abbr if err != nil { t.Fatal(err) }
|
2015-02-24 05:45:22 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
|
2017-02-11 08:01:38 -05:00
|
|
|
# error snippet in log.Fatal
|
|
|
|
snippet errl
|
2018-02-04 06:35:08 -05:00
|
|
|
abbr if err != nil { log.Fatal(err) }
|
2017-02-11 08:01:38 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
# error snippet with two return values
|
|
|
|
snippet errn,
|
|
|
|
abbr if err != nil { return [...], err }
|
|
|
|
if err != nil {
|
2016-02-20 08:13:10 -05:00
|
|
|
return ${1:nil}, err
|
2015-01-18 07:58:28 -05:00
|
|
|
}
|
2014-10-31 17:30:24 -04:00
|
|
|
${0}
|
2015-01-18 07:58:28 -05:00
|
|
|
|
2015-03-14 16:02:10 -04:00
|
|
|
# error snippet handle and return
|
|
|
|
snippet errh
|
2018-02-04 06:35:08 -05:00
|
|
|
abbr if err != nil { ... return }
|
2015-03-14 16:02:10 -04:00
|
|
|
if err != nil {
|
|
|
|
${1}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
${0}
|
|
|
|
|
2016-07-16 14:30:35 -04:00
|
|
|
# error snippet with panic
|
|
|
|
snippet errp
|
2018-02-04 06:35:08 -05:00
|
|
|
abbr if err != nil { panic(...) }
|
2016-07-16 14:30:35 -04:00
|
|
|
if err != nil {
|
|
|
|
panic(${1})
|
|
|
|
}
|
|
|
|
${0}
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
# json snippet
|
|
|
|
snippet json
|
|
|
|
abbr \`json:key\`
|
|
|
|
\`json:"${1:keyName}"\`
|
2016-02-20 08:13:10 -05:00
|
|
|
|
2016-08-02 08:48:32 -04:00
|
|
|
# yaml snippet
|
|
|
|
snippet yaml
|
|
|
|
abbr \`yaml:key\`
|
|
|
|
\`yaml:"${1:keyName}"\`
|
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
# fallthrough
|
|
|
|
snippet ft
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr fallthrough
|
2014-10-31 17:30:24 -04:00
|
|
|
fallthrough
|
|
|
|
# for loop
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet for
|
|
|
|
abbr for ... { ... }
|
|
|
|
for ${1} {
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# for integer loop
|
|
|
|
snippet fori
|
|
|
|
abbr for 0..N-1 { ... }
|
|
|
|
for ${1:i} := 0; $1 < ${2:N}; $1++ {
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# for range loop
|
|
|
|
snippet forr
|
|
|
|
abbr for k, v := range items { ... }
|
|
|
|
for ${2:k}, ${3:v} := range ${1} {
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# function
|
|
|
|
snippet func
|
|
|
|
abbr func function(...) [error] { ... }
|
|
|
|
func ${1:function}(${2}) ${3:error }{
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
|
|
|
# Fmt Printf debug
|
|
|
|
snippet ff
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr fmt.Printf(...)
|
|
|
|
fmt.Printf("${1} = %+v\n", $1)
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
# Fmt Println debug
|
|
|
|
snippet fn
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr fmt.Println(...)
|
2014-10-31 17:30:24 -04:00
|
|
|
fmt.Println("${1}")
|
2018-03-31 10:56:26 -04:00
|
|
|
# Fmt Errorf
|
|
|
|
snippet fe
|
|
|
|
abbr fmt.Errorf(...)
|
|
|
|
fmt.Errorf("${1}")
|
2014-10-31 17:30:24 -04:00
|
|
|
# log printf
|
|
|
|
snippet lf
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr log.Printf(...)
|
|
|
|
log.Printf("${1} = %+v\n", $1)
|
|
|
|
# log println
|
|
|
|
snippet ln
|
|
|
|
abbr log.Println(...)
|
2014-10-31 17:30:24 -04:00
|
|
|
log.Println("${1}")
|
|
|
|
# make
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet make
|
|
|
|
abbr make(Type, size)
|
|
|
|
make(${1:[]string}, ${2:0})${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
# map
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet map
|
|
|
|
abbr map[Type]Type
|
2014-10-31 17:30:24 -04:00
|
|
|
map[${1:string}]${0:int}
|
|
|
|
# main()
|
|
|
|
snippet main
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr func main() { ... }
|
|
|
|
options head
|
2014-10-31 17:30:24 -04:00
|
|
|
func main() {
|
2015-01-18 07:58:28 -05:00
|
|
|
${0}
|
|
|
|
}
|
|
|
|
# method
|
|
|
|
snippet meth
|
|
|
|
abbr func (self Type) Method(...) [error] { ... }
|
|
|
|
regexp /^meth/
|
|
|
|
func (${1:self} ${2:Type}) ${3:Do}(${4}) ${5:error }{
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# ok
|
|
|
|
snippet ok
|
|
|
|
abbr if !ok { ... }
|
|
|
|
if !ok {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
# package
|
|
|
|
snippet package
|
|
|
|
abbr package ...
|
|
|
|
// Package $1 provides ${2:...}
|
|
|
|
package ${1:main}
|
2014-10-31 17:30:24 -04:00
|
|
|
${0}
|
|
|
|
# panic
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet panic
|
|
|
|
alias pn
|
|
|
|
abbr panic("...")
|
|
|
|
panic("${0}")
|
2014-10-31 17:30:24 -04:00
|
|
|
# return
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet return
|
|
|
|
alias rt
|
|
|
|
abbr return ...
|
2014-10-31 17:30:24 -04:00
|
|
|
return ${0}
|
|
|
|
# select
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet select
|
|
|
|
abbr select { case a := <-chan: ... }
|
2014-10-31 17:30:24 -04:00
|
|
|
select {
|
|
|
|
case ${1:v1} := <-${2:chan1}
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
# struct
|
|
|
|
snippet st
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr type T struct { ... }
|
|
|
|
type ${1:Type} struct {
|
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
|
|
|
# switch
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet switch
|
|
|
|
abbr switch x { ... }
|
2014-10-31 17:30:24 -04:00
|
|
|
switch ${1:var} {
|
|
|
|
case ${2:value1}:
|
|
|
|
${0}
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# sprintf
|
2014-10-31 17:30:24 -04:00
|
|
|
snippet sp
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr fmt.Sprintf(...)
|
2014-10-31 17:30:24 -04:00
|
|
|
fmt.Sprintf("%${1:s}", ${2:var})
|
|
|
|
# goroutine named function
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet go
|
|
|
|
abbr go someFunc(...)
|
2014-10-31 17:30:24 -04:00
|
|
|
go ${1:funcName}(${0})
|
|
|
|
# goroutine anonymous function
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet gof
|
|
|
|
abbr go func(...) { ... }(...)
|
|
|
|
go func(${1}) {
|
|
|
|
${3:/* TODO */}
|
|
|
|
}(${2})
|
2014-10-31 17:30:24 -04:00
|
|
|
# test function
|
|
|
|
snippet test
|
2015-01-18 07:58:28 -05:00
|
|
|
abbr func TestXYZ(t *testing.T) { ... }
|
2014-10-31 17:30:24 -04:00
|
|
|
func Test${1:Function}(t *testing.T) {
|
2015-01-18 07:58:28 -05:00
|
|
|
${0}
|
2014-10-31 17:30:24 -04:00
|
|
|
}
|
2015-02-24 05:45:22 -05:00
|
|
|
# test server
|
|
|
|
snippet tsrv
|
|
|
|
abbr ts := httptest.NewServer(...)
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintln(w, ${1:`response`})
|
|
|
|
}))
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
//Use testing server url (type string) somewhere
|
|
|
|
${0:someUrl} = ts.URL
|
|
|
|
# test error
|
|
|
|
snippet ter
|
|
|
|
abbr if err != nil { t.Errorf(...) }
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("${1}")
|
|
|
|
}
|
|
|
|
# test fatal error
|
|
|
|
snippet terf
|
|
|
|
abbr if err != nil { t.Fatalf(...) }
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("${1}")
|
|
|
|
}
|
2016-05-14 07:57:54 -04:00
|
|
|
# test example
|
|
|
|
snippet example
|
2016-06-11 09:56:50 -04:00
|
|
|
func Example${1:Method}() {
|
|
|
|
${0}
|
|
|
|
// Output:
|
|
|
|
}
|
2016-05-14 07:57:54 -04:00
|
|
|
# test benchmark
|
|
|
|
snippet benchmark
|
2016-06-11 09:56:50 -04:00
|
|
|
func Benchmark${1:Method}(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
${0}
|
|
|
|
}
|
2016-05-14 07:57:54 -04:00
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
# variable declaration
|
|
|
|
snippet var
|
|
|
|
abbr var x Type [= ...]
|
|
|
|
var ${1:x} ${2:Type}${3: = ${0:value\}}
|
|
|
|
# variables declaration
|
|
|
|
snippet vars
|
|
|
|
abbr var ( ... )
|
|
|
|
var (
|
|
|
|
${1:x} ${2:Type}${3: = ${0:value\}}
|
|
|
|
)
|
2015-03-14 16:02:10 -04:00
|
|
|
# equals fails the test if exp is not equal to act.
|
|
|
|
snippet eq
|
|
|
|
abbr equals: test two identifiers with DeepEqual
|
|
|
|
if !reflect.DeepEqual(${1:expected}, ${2:actual}) {
|
|
|
|
_, file, line, _ := runtime.Caller(0)
|
|
|
|
fmt.Printf("%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, $1, $2)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
2016-05-14 07:57:54 -04:00
|
|
|
|
|
|
|
snippet hf
|
|
|
|
abbr http.HandlerFunc
|
|
|
|
func ${1:handler}(w http.ResponseWriter, r *http.Request) {
|
|
|
|
${0:fmt.Fprintf(w, "hello world")}
|
|
|
|
}
|
|
|
|
|
|
|
|
snippet hhf
|
|
|
|
abbr mux.HandleFunc(...)
|
|
|
|
${1:http}.HandleFunc("${2:/}", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
${0:fmt.Fprintf(w, "hello world")}
|
|
|
|
})
|