123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- # shorthand variable declaration
- snippet :
- abbr v := value
- ${1} := ${0}
- # anonymous function
- snippet anon
- abbr fn := func() { ... }
- ${1:fn} := func() {
- ${0}
- }
- # append
- snippet ap
- abbr append(slice, value)
- append(${1:slice}, ${0:value})
- # append assign
- snippet ap=
- abbr slice = append(slice, value)
- ${1:slice} = append($1, ${0:value})
- # break
- snippet br
- abbr break
- break
- # channel
- snippet ch
- abbr chan Type
- chan ${0:int}
- # case
- snippet case
- abbr case ...:
- case ${1:value}:
- ${0}
- # 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}
- )
- # constants with iota
- snippet iota
- abbr const ( ... = iota )
- const (
- ${1:NAME} ${2:Type} = iota
- ${0}
- )
- # continue
- snippet cn
- abbr continue
- continue
- # default case
- snippet default
- abbr default: ...
- default:
- ${0}
- # defer
- snippet df
- abbr defer someFunction()
- defer ${1:func}(${2})
- ${0}
- snippet def
- abbr defer func() { ... }
- defer func() {
- ${0}
- }()
- # defer recover
- snippet defr
- 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
- snippet import
- abbr import ( ... )
- import (
- "${1:package}"
- )
- # full interface snippet
- snippet interface
- abbr interface I { ... }
- type ${1:Interface} interface {
- ${2:/* TODO: add methods */}
- }
- # if condition
- snippet if
- abbr if ... { ... }
- if ${1:condition} {
- ${0}
- }
- # else snippet
- abbr else { ... }
- snippet else
- else {
- ${0}
- }
- # if inline error
- snippet ife
- abbr if err := ...; err != nil { ... }
- if err := ${1:condition}; err != nil {
- ${0}
- }
- # error snippet
- snippet errn
- abbr if err != nil { return err }
- if err != nil {
- return err
- }
- ${0}
- # error snippet in TestFunc
- snippet errt
- abbr if err != nil { t.Fatal(err) }
- if err != nil {
- t.Fatal(err)
- }
- # error snippet in log.Fatal
- snippet errl
- abbr if err != nil { log.Fatal(err) }
- if err != nil {
- log.Fatal(err)
- }
- # error snippet with two return values
- snippet errn,
- abbr if err != nil { return [...], err }
- if err != nil {
- return ${1:nil}, err
- }
- ${0}
- # error snippet handle and return
- snippet errh
- abbr if err != nil { ... return }
- if err != nil {
- ${1}
- return
- }
- ${0}
- # error snippet with panic
- snippet errp
- abbr if err != nil { panic(...) }
- if err != nil {
- panic(${1})
- }
- ${0}
- # json snippet
- snippet json
- abbr \`json:key\`
- \`json:"${1:keyName}"\`
- # yaml snippet
- snippet yaml
- abbr \`yaml:key\`
- \`yaml:"${1:keyName}"\`
- # fallthrough
- snippet ft
- abbr fallthrough
- fallthrough
- # for loop
- snippet for
- abbr for ... { ... }
- for ${1} {
- ${0}
- }
- # for integer loop
- snippet fori
- abbr for 0..N-1 { ... }
- for ${1:i} := 0; $1 < ${2:N}; $1++ {
- ${0}
- }
- # for range loop
- snippet forr
- abbr for k, v := range items { ... }
- for ${2:k}, ${3:v} := range ${1} {
- ${0}
- }
- # function
- snippet func
- abbr func function(...) [error] { ... }
- func ${1:function}(${2}) ${3:error }{
- ${0}
- }
- # Fmt Printf debug
- snippet ff
- abbr fmt.Printf(...)
- fmt.Printf("${1} = %+v\n", $1)
- ${0}
- # Fmt Println debug
- snippet fn
- abbr fmt.Println(...)
- fmt.Println("${1}")
- # Fmt Errorf
- snippet fe
- abbr fmt.Errorf(...)
- fmt.Errorf("${1}")
- # log printf
- snippet lf
- abbr log.Printf(...)
- log.Printf("${1} = %+v\n", $1)
- # log println
- snippet ln
- abbr log.Println(...)
- log.Println("${1}")
- # make
- snippet make
- abbr make(Type, size)
- make(${1:[]string}, ${2:0})${0}
- # map
- snippet map
- abbr map[Type]Type
- map[${1:string}]${0:int}
- # main()
- snippet main
- abbr func main() { ... }
- options head
- func main() {
- ${0}
- }
- # method
- snippet meth
- abbr func (self Type) Method(...) [error] { ... }
- regexp /^meth/
- func (${1:self} ${2:Type}) ${3:Do}(${4}) ${5:error }{
- ${0}
- }
- # ok
- snippet ok
- abbr if !ok { ... }
- if !ok {
- ${0}
- }
- # package
- snippet package
- abbr package ...
- // Package $1 provides ${2:...}
- package ${1:main}
- ${0}
- # panic
- snippet panic
- alias pn
- abbr panic("...")
- panic("${0}")
- # return
- snippet return
- alias rt
- abbr return ...
- return ${0}
- # select
- snippet select
- abbr select { case a := <-chan: ... }
- select {
- case ${1:v1} := <-${2:chan1}
- ${0}
- }
- # struct
- snippet st
- abbr type T struct { ... }
- type ${1:Type} struct {
- ${0}
- }
- # switch
- snippet switch
- abbr switch x { ... }
- switch ${1:var} {
- case ${2:value1}:
- ${0}
- }
- # sprintf
- snippet sp
- abbr fmt.Sprintf(...)
- fmt.Sprintf("%${1:s}", ${2:var})
- # goroutine named function
- snippet go
- abbr go someFunc(...)
- go ${1:funcName}(${0})
- # goroutine anonymous function
- snippet gof
- abbr go func(...) { ... }(...)
- go func(${1}) {
- ${3:/* TODO */}
- }(${2})
- # test function
- snippet test
- abbr func TestXYZ(t *testing.T) { ... }
- func Test${1:Function}(t *testing.T) {
- ${0}
- }
- # 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}")
- }
- # test example
- snippet example
- func Example${1:Method}() {
- ${0}
- // Output:
- }
- # test benchmark
- snippet benchmark
- func Benchmark${1:Method}(b *testing.B) {
- for i := 0; i < b.N; i++ {
- ${0}
- }
- }
- # 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\}}
- )
- # 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()
- }
- 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")}
- })
|