go.snippets 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # append
  2. snippet ap
  3. append(${1:slice}, ${2:value})
  4. # bool
  5. snippet bl
  6. bool
  7. # byte
  8. snippet bt
  9. byte
  10. # break
  11. snippet br
  12. break
  13. # channel
  14. snippet ch
  15. chan ${1:int}
  16. # case
  17. snippet cs
  18. case ${1:value}:
  19. ${2:/* code */}
  20. # const
  21. snippet c
  22. const ${1:NAME} = ${2:0}
  23. # constants with iota
  24. snippet co
  25. const (
  26. ${1:NAME1} = iota
  27. ${2:NAME2}
  28. )
  29. # continue
  30. snippet cn
  31. continue
  32. # defer
  33. snippet df
  34. defer ${1:func}()
  35. # defer recover
  36. snippet dfr
  37. defer func() {
  38. if err := recover(); err != nil {
  39. ${1:/* code */}
  40. }
  41. }()
  42. # gpl
  43. snippet gpl
  44. /*
  45. * This program is free software; you can redistribute it and/or modify
  46. * it under the terms of the GNU General Public License as published by
  47. * the Free Software Foundation; either version 2 of the License, or
  48. * (at your option) any later version.
  49. *
  50. * This program is distributed in the hope that it will be useful,
  51. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  52. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  53. * GNU General Public License for more details.
  54. *
  55. * You should have received a copy of the GNU General Public License
  56. * along with this program; if not, write to the Free Software
  57. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  58. *
  59. * Copyright (C) ${1:Author}, `strftime("%Y")`
  60. */
  61. ${2}
  62. # int
  63. snippet i
  64. int
  65. # import
  66. snippet im
  67. import (
  68. "${1:package}"
  69. )
  70. # interface
  71. snippet in
  72. interface{}
  73. # full interface snippet
  74. snippet inf
  75. interface ${1:name} {
  76. ${2:/* methods */}
  77. }${3}
  78. # if condition
  79. snippet if
  80. if ${1:/* condition */} {
  81. ${2:/* code */}
  82. }
  83. # else snippet
  84. snippet el
  85. else {
  86. ${1}
  87. }
  88. # error snippet
  89. snippet ir
  90. if err != nil {
  91. return err
  92. }
  93. ${1}
  94. # false
  95. snippet f
  96. false
  97. # fallthrough
  98. snippet ft
  99. fallthrough
  100. # float
  101. snippet fl
  102. float32
  103. # float32
  104. snippet f3
  105. float32
  106. # float64
  107. snippet f6
  108. float64
  109. # if else
  110. snippet ie
  111. if ${1:/* condition */} {
  112. ${2:/* code */}
  113. } else {
  114. ${3}
  115. }
  116. # for loop
  117. snippet fo
  118. for ${2:i} = 0; $2 < ${1:count}; $2${3:++} {
  119. ${4:/* code */}
  120. }
  121. # for range loop
  122. snippet fr
  123. for ${1:k}, ${2:v} := range ${3} {
  124. ${4:/* code */}
  125. }
  126. # function simple
  127. snippet fun
  128. func ${1:funcName}(${2}) ${3:os.Error} {
  129. ${4:/* code */}
  130. }
  131. # function on receiver
  132. snippet fum
  133. func (self ${1:type}) ${2:funcName}(${3}) ${4:os.Error} {
  134. ${5:/* code */}
  135. }
  136. # make
  137. snippet mk
  138. make(${1:[]string}, ${2:0})
  139. # map
  140. snippet mp
  141. map[${1:string}]${2:int}
  142. # main()
  143. snippet main
  144. func main() {
  145. ${1:/* code */}
  146. }
  147. # new
  148. snippet nw
  149. new(${1:type})
  150. # panic
  151. snippet pn
  152. panic("${1:msg}")
  153. # print
  154. snippet pr
  155. fmt.Printf("${1:%s}\n", ${2:var})${3}
  156. # range
  157. snippet rn
  158. range ${1}
  159. # return
  160. snippet rt
  161. return ${1}
  162. # result
  163. snippet rs
  164. result
  165. # select
  166. snippet sl
  167. select {
  168. case ${1:v1} := <-${2:chan1}
  169. ${3:/* code */}
  170. case ${4:v2} := <-${5:chan2}
  171. ${6:/* code */}
  172. default:
  173. ${7:/* code */}
  174. }
  175. # string
  176. snippet sr
  177. string
  178. # struct
  179. snippet st
  180. struct ${1:name} {
  181. ${2:/* data */}
  182. }${4}
  183. # switch
  184. snippet sw
  185. switch ${1:var} {
  186. case ${2:value1}:
  187. ${3:/* code */}
  188. case ${4:value2}:
  189. ${5:/* code */}
  190. default:
  191. ${6:/* code */}
  192. }
  193. snippet sp
  194. fmt.Sprintf("${1:%s}", ${2:var})${3}
  195. # true
  196. snippet t
  197. true
  198. # variable declaration
  199. snippet v
  200. var ${1:t} ${2:string}