From 016d197855d8724570d4b588d22938eacdc3cd7a Mon Sep 17 00:00:00 2001 From: Alexilator Date: Mon, 14 Apr 2025 14:28:34 +0000 Subject: [PATCH] Add go.json --- go.json | 570 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 570 insertions(+) create mode 100644 go.json diff --git a/go.json b/go.json new file mode 100644 index 0000000..648261f --- /dev/null +++ b/go.json @@ -0,0 +1,570 @@ +{ + "single import": { + "prefix": "im", + "body": "import \"${1:package}\"", + "description": "Snippet for import statement" + }, + "multiple imports": { + "prefix": "ims", + "body": "import (\n\t\"${1:package}\"\n)", + "description": "Snippet for a import block" + }, + "single constant": { + "prefix": "co", + "body": "const ${1:name} = ${2:value}", + "description": "Snippet for a constant" + }, + "multiple constants": { + "prefix": "cos", + "body": "const (\n\t${1:name} = ${2:value}\n)", + "description": "Snippet for a constant block" + }, + "type function declaration": { + "prefix": "tyf", + "body": "type ${1:name} func($3) $4", + "description": "Snippet for a type function declaration" + }, + "type interface declaration": { + "prefix": "tyi", + "body": "type ${1:name} interface {\n\t$0\n}", + "description": "Snippet for a type interface" + }, + "type struct declaration": { + "prefix": "tys", + "body": "type ${1:name} struct {\n\t$0\n}", + "description": "Snippet for a struct declaration" + }, + "package main and main function": { + "prefix": "pkgm", + "body": "package main\n\nfunc main() {\n\t$0\n}", + "description": "Snippet for main package & function" + }, + "function declaration": { + "prefix": "func", + "body": "func $1($2) $3 {\n\t$0\n}", + "description": "Snippet for function declaration" + }, + "variable declaration": { + "prefix": "var", + "body": "var ${1:name} ${2:type}", + "description": "Snippet for a variable" + }, + "variables declaration": { + "prefix": "vars", + "body": "var (\n\t${1:name} ${2:type} = ${3:value}\n)", + "description": "Snippet for a variable" + }, + "switch statement": { + "prefix": "switch", + "body": "switch ${1:expression} {\ncase ${2:condition}:\n\t$0\n}", + "description": "Snippet for switch statement" + }, + "select statement": { + "prefix": "sel", + "body": "select {\ncase ${1:condition}:\n\t$0\n}", + "description": "Snippet for select statement" + }, + "case clause": { + "prefix": "cs", + "body": "case ${1:condition}:$0", + "description": "Snippet for case clause" + }, + "for statement": { + "prefix": "for", + "body": "for ${1}{\n\t$0\n}", + "description": "Snippet for a pure for loop" + }, + "for n statement": { + "prefix": "fori", + "body": "for ${1:i} := ${2:0}; $1 < ${3:count}; $1${4:++} {\n\t$0\n}", + "description": "Snippet for a for loop" + }, + "for range statement": { + "prefix": "forr", + "body": "for ${1:_, }${2:v} := range ${3:v} {\n\t$0\n}", + "description": "Snippet for a for range loop" + }, + "channel declaration": { + "prefix": "ch", + "body": "chan ${1:type}", + "description": "Snippet for a channel" + }, + "map declaration": { + "prefix": "map", + "body": "map[${1:type}]${2:type}", + "description": "Snippet for a map" + }, + "empty interface": { + "prefix": "in", + "body": "interface{}", + "description": "Snippet for empty interface" + }, + "if statement": { + "prefix": "if", + "body": "if ${1:condition} {\n\t$0\n}", + "description": "Snippet for if statement" + }, + "else branch": { + "prefix": "el", + "body": "else {\n\t$0\n}", + "description": "Snippet for else branch" + }, + "if else statement": { + "prefix": "ife", + "body": "if ${1:condition} {\n\t$2\n} else {\n\t$0\n}", + "description": "Snippet for if else" + }, + "if err != nil": { + "prefix": "ir", + "body": "if err != nil {\n\treturn ${1:nil}, ${2:err}\n}", + "description": "Snippet for if err != nil" + }, + "fmt.Println": { + "prefix": "fp", + "body": "fmt.Println(\"$1\")", + "description": "Snippet for fmt.Println()" + }, + "fmt.Printf": { + "prefix": "ff", + "body": "fmt.Printf(\"$1\", ${2:var})", + "description": "Snippet for fmt.Printf()" + }, + "log.Println": { + "prefix": "lp", + "body": "log.Println(\"$1\")", + "description": "Snippet for log.Println()" + }, + "log.Printf": { + "prefix": "lf", + "body": "log.Printf(\"$1\", ${2:var})", + "description": "Snippet for log.Printf()" + }, + "log variable content": { + "prefix": "lv", + "body": "log.Printf(\"${1:var}: %#+v\\\\n\", ${1:var})", + "description": "Snippet for log.Printf() with variable content" + }, + "t.Log": { + "prefix": "tl", + "body": "t.Log(\"$1\")", + "description": "Snippet for t.Log()" + }, + "t.Logf": { + "prefix": "tlf", + "body": "t.Logf(\"$1\", ${2:var})", + "description": "Snippet for t.Logf()" + }, + "t.Logf variable content": { + "prefix": "tlv", + "body": "t.Logf(\"${1:var}: %#+v\\\\n\", ${1:var})", + "description": "Snippet for t.Logf() with variable content" + }, + "make(...)": { + "prefix": "make", + "body": "make(${1:type}, ${2:0})", + "description": "Snippet for make statement" + }, + "new(...)": { + "prefix": "new", + "body": "new(${1:type})", + "description": "Snippet for new statement" + }, + "panic(...)": { + "prefix": "pn", + "body": "panic(\"$0\")", + "description": "Snippet for panic" + }, + "http ResponseWriter *Request": { + "prefix": "wr", + "body": "${1:w} http.ResponseWriter, ${2:r} *http.Request", + "description": "Snippet for http Response" + }, + "http.HandleFunc": { + "prefix": "hf", + "body": "${1:http}.HandleFunc(\"${2:/}\", ${3:handler})", + "description": "Snippet for http.HandleFunc()" + }, + "http handler declaration": { + "prefix": "hand", + "body": "func $1(${2:w} http.ResponseWriter, ${3:r} *http.Request) {\n\t$0\n}", + "description": "Snippet for http handler declaration" + }, + "http.Redirect": { + "prefix": "rd", + "body": "http.Redirect(${1:w}, ${2:r}, \"${3:/}\", ${4:http.StatusFound})", + "description": "Snippet for http.Redirect()" + }, + "http.Error": { + "prefix": "herr", + "body": "http.Error(${1:w}, ${2:err}.Error(), ${3:http.StatusInternalServerError})", + "description": "Snippet for http.Error()" + }, + "http.ListenAndServe": { + "prefix": "las", + "body": "http.ListenAndServe(\"${1::8080}\", ${2:nil})", + "description": "Snippet for http.ListenAndServe" + }, + "http.Serve": { + "prefix": "sv", + "body": "http.Serve(\"${1::8080}\", ${2:nil})", + "description": "Snippet for http.Serve" + }, + "goroutine anonymous function": { + "prefix": "go", + "body": "go func($1) {\n\t$0\n}($2)", + "description": "Snippet for anonymous goroutine declaration" + }, + "goroutine function": { + "prefix": "gf", + "body": "go ${1:func}($0)", + "description": "Snippet for goroutine declaration" + }, + "defer statement": { + "prefix": "df", + "body": "defer ${1:func}($0)", + "description": "Snippet for defer statement" + }, + "test function": { + "prefix": "tf", + "body": "func Test$1(t *testing.T) {\n\t$0\n}", + "description": "Snippet for Test function" + }, + "test main": { + "prefix": "tm", + "body": "func TestMain(m *testing.M) {\n\t$1\n\n\tos.Exit(m.Run())\n}", + "description": "Snippet for TestMain function" + }, + "benchmark function": { + "prefix": "bf", + "body": "func Benchmark$1(b *testing.B) {\n\tfor ${2:i} := 0; ${2:i} < b.N; ${2:i}++ {\n\t\t$0\n\t}\n}", + "description": "Snippet for Benchmark function" + }, + "example function": { + "prefix": "ef", + "body": "func Example$1() {\n\t$2\n\t//Output:\n\t$3\n}", + "description": "Snippet for Example function" + }, + "table driven test": { + "prefix": "tdt", + "body": "func Test$1(t *testing.T) {\n\ttestCases := []struct {\n\t\tdesc\tstring\n\t\t$2\n\t}{\n\t\t{\n\t\t\tdesc: \"$3\",\n\t\t\t$4\n\t\t},\n\t}\n\tfor _, tC := range testCases {\n\t\tt.Run(tC.desc, func(t *testing.T) {\n\t\t\t$0\n\t\t})\n\t}\n}", + "description": "Snippet for table driven test" + }, + "init function": { + "prefix": "finit", + "body": "func init() {\n\t$1\n}", + "description": "Snippet for init function" + }, + "main function": { + "prefix": "fmain", + "body": "func main() {\n\t$1\n}", + "description": "Snippet for main function" + }, + "method declaration": { + "prefix": [ + "meth", + "fum" + ], + "body": "func (${1:receiver} ${2:type}) ${3:method}($4) $5 {\n\t$0\n}", + "description": "Snippet for method declaration" + }, + "hello world web app": { + "prefix": "helloweb", + "body": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"time\"\n)\n\nfunc greet(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Hello World! %s\", time.Now())\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", greet)\n\thttp.ListenAndServe(\":8080\", nil)\n}", + "description": "Snippet for sample hello world webapp" + }, + "sort implementation": { + "prefix": "sort", + "body": "type ${1:SortBy} []${2:Type}\n\nfunc (a $1) Len() int { return len(a) }\nfunc (a $1) Swap(i, j int) { a[i], a[j] = a[j], a[i] }\nfunc (a $1) Less(i, j int) bool { ${3:return a[i] < a[j]} }", + "description": "Snippet for a custom sort.Sort interface implementation, for a given slice type." + }, + "json tag": { + "prefix": "json", + "body": "`json:\"$1\"`", + "description": "Snippet for struct json tag" + }, + "xml tag": { + "prefix": "xml", + "body": "`xml:\"$1\"`", + "description": "Snippet for struct xml tag" + }, + "if key in a map": { + "prefix": "om", + "body": "if ${1:value}, ok := ${2:map}[${3:key}]; ok {\n\t$4\n}" + }, + "init var": { + "prefix": "vv", + "body": [ + "${2:varName} := ${1:value}" + ] + }, + "Case default": { + "prefix": "def", + "body": [ + "default:" + ] + }, + "Close": { + "prefix": "cl", + "body": [ + "close(${0:closable})" + ] + }, + "Goroutine anonymous func": { + "prefix": "gofunc", + "body": [ + "go func(){", + " $0", + "}()" + ] + }, + "Slice Remove": { + "prefix": "sr", + "body": [ + "${1:slice} = append(${1:slice}[:${2:index}], ${1:slice}[${2:index}+1:]...)" + ] + }, + "Defer anonymous func": { + "prefix": "defunc", + "body": [ + "defer func() {", + " $0", + "}()" + ] + }, + "if ok": { + "prefix": "ifok", + "body": [ + "if ${1:value}, ok := $2; ok {", + " $0", + "}" + ] + }, + "delete": { + "prefix": "del", + "body": [ + "delete(${1:map}, \"${2:key}\")" + ] + }, + "append": { + "prefix": "ap", + "body": [ + "${1:slice} = append(${1:slice}, ${0:element})" + ] + }, + "log.Printf": { + "prefix": "lo", + "body": [ + "log.Printf(\"${1:%+v}\\n\", $0)" + ] + }, + "log.Printf err": { + "prefix": "le", + "body": [ + "log.Printf(\"${1:%+v}\\n\", err)" + ] + }, + "log.Fatal": { + "prefix": "lf", + "body": [ + "log.Fatal(${0:err})" + ] + }, + "log.Fatalf": { + "prefix": "lff", + "body": [ + "log.Fatalf(\"${1:%+v}\\n\", ${0:err})" + ] + }, + "log.Errorf": { + "prefix": "lef", + "body": [ + "log.Errorf(\"${1:%+v}\\n\", ${0:err})" + ] + }, + "fmt.Sprintf": { + "prefix": "fms", + "body": [ + "fmt.Sprintf(\"${1:%+v}\", $0)" + ] + }, + "fmt.Errorf": { + "prefix": "fme", + "body": [ + "fmt.Errorf(\"${1:%+v}\", ${0:err})" + ] + }, + "ctx context.Context": { + "prefix": "ctx", + "body": [ + "ctx context.Context", + ], + }, + "if error": { + "prefix": "ier", + "body": [ + "if err != nil {", + " $0", + "}" + ] + }, + "errors.Is()": { + "prefix": "is", + "body": [ + "if errors.Is(err, ${1:exec.ErrNotFound}) {", + " $0", + "}" + ] + }, + "errors.As()": { + "prefix": "as", + "body": [ + "var e ${1:*exec.Error}", + "if errors.As(err, &e) {", + " $0", + "}" + ] + }, + "Error with Stack": { + "prefix": "es", + "body": [ + "errors.WithStack(err)" + ] + }, + "Error with Message": { + "prefix": "em", + "body": [ + "errors.WithMessage(err, ${0:message})" + ] + }, + "Error with Messagef": { + "prefix": "emf", + "body": [ + "errors.WithMessagef(err, ${1:format}, ${0:args})" + ] + }, + "Return Nil": { + "prefix": "rn", + "body": [ + "return nil" + ] + }, + "Return Nil & err": { + "prefix": "rne", + "body": [ + "return nil, err" + ] + }, + "Return err": { + "prefix": "re", + "body": [ + "return err" + ] + }, + "Struct": { + "prefix": "st", + "body": [ + "type ${1:structName} struct {", + " $0", + "}" + ] + }, + "Struct Field": { + "prefix": "sf", + "body": [ + "${1:fieldName} ${2:string}" + ] + }, + "Struct Tag": { + "prefix": "stt", + "body": [ + "`${1:json}:\"${2:jsonFieldName}\"`" + ] + }, + "Interface": { + "prefix": "inte", + "body": [ + "type ${1:interfaceName} interface {", + " $0", + "}" + ] + }, + "sync.Mutex Lock and defer Unlock": { + "prefix": "lock", + "body": [ + "${1:mu}.Lock()", + "defer ${1:mu}.Unlock()" + ] + }, + "New Constructor Method": { + "prefix": "ne", + "body": [ + "func New$1($2) *$1 {", + " $3", + " return &$1{", + " $0", + " }", + "}" + ] + }, + "For Range": { + "prefix": "fr", + "body": [ + "for _, ${1:v} := range ${2:values} {", + " $0", + "}" + ] + }, + "For Range Chan": { + "prefix": "frr", + "body": [ + "for ${1:v} := range ${2:channel} {", + " $0", + "}" + ] + }, + "Non-blocking Channel Send": { + "prefix": "nb", + "body": [ + "select {", + "case $1 <- $0:", + "default:", + "}" + ] + }, + "Testify Assert Nil": { + "prefix": "anil", + "body": [ + "assert.Nil(t, ${1:actual})", + "$0" + ] + }, + "Testify Assert Not Nil": { + "prefix": "annil", + "body": [ + "assert.NotNil(t, ${1:actual})", + "$0" + ] + }, + "Testify Assert Equal": { + "prefix": "aeq", + "body": [ + "assert.Equal(t, ${1:expected}, ${2:actual})", + "$0" + ] + }, + "Testify Assert No Error": { + "prefix": "anerr", + "body": [ + "assert.NoError(t, ${1:err})", + "$0" + ] + }, + "Logrus import": { + "description": "logrus import snippet that 'overwrites' standard log lib", + "prefix": "logrus", + "body": [ + "${1:log} \"github.com/sirupsen/logrus\"", + "$0" + ] + } +} \ No newline at end of file