xgqfrms / vscode

:cn: :rocket: Visual Studio Code & VSCode Code Snippets All in One 🎉
https://vscode.xgqfrms.xyz
MIT License
3 stars 1 forks source link

vscode-snippets & go.json #20

Open xgqfrms opened 5 years ago

xgqfrms commented 5 years ago

vscode-snippets & go.json

https://github.com/tj/vscode-snippets/blob/master/go.json


{
    "params": {
      "prefix": "params",
      "body": [
        "// $1Input params.",
        "type $1Input struct {",
        "  $0",
        "}",
        "",
        "// $1Output params.",
        "type $1Output struct {",
        "  ",
        "}"
      ]
    },

    "string enum": {
      "prefix": "string-enum",
      "body": [
        "// $1 $2.",
        "type $1 string",
        "",
        "// $1s available.",
        "const (",
          "  $0",
        ")",
      ]
    },

    "db": {
      "prefix": "db",
      "body": [
        "db *sqlx.DB"
      ]
    },

    "if": {
      "prefix": "if",
      "body": [
        "if ${2:v}, ok := $1; ok {",
        "  $0",
        "}"
      ]
    },

    "options": {
      "prefix": "options",
      "body": [
        "// Option function.",
        "type Option func(*$1)",
        "",
        "// New $2 with the given options.",
        "func New(options ...Option) *$1 {",
        "  var v $1",
        "  for _, o := range options {",
        "     o(&v)",
        "  }",
        "  return &v",
        "}"
      ]
    },

    "option": {
      "prefix": "o",
      "body": [
        "// With$1 $0.",
        "func With$1($2) Option {",
        "  return func($3) {",
        "    $4",
        "  }",
        "}"
      ]
    },

    "log error": {
      "prefix": "le",
      "body": [
        "logs.WithError(err).Error(\"$1\")"
      ]
    },

    "log info": {
      "prefix": "li",
      "body": [
        "logs.Info(\"$1\")"
      ]
    },

    "log with fields": {
      "prefix": "lw",
      "body": [
        "logs.WithFields(log.Fields{",
        "  $0",
        "})"
      ]
    },

    "delete": {
      "prefix": "d",
      "body": [
        "delete($1, \"$2\")"
      ]
    },

    "Pretty Print": {
      "prefix": "pp",
      "body": [
        "pretty.Print($0)",
      ]
    },

    "fmt.Printf": {
      "prefix": "p",
      "body": [
        "fmt.Printf(\"${1:%#v}\\n\", $0)"
      ]
    },

    "log.Printf": {
      "prefix": "l",
      "body": [
        "log.Printf(\"${1:%v}\\n\", $0)"
      ]
    },

    "log.Fatalf": {
      "prefix": "fa",
      "body": [
        "log.Fatalf(\"error: %s\\n\", ${0:err})"
      ]
    },

    "Append": {
      "prefix": "a",
      "body": [
        "$1 = append($1, $0)"
      ]
    },

    "Build Tag": {
      "prefix": "build",
      "body": [
        "// +build ${0:js}"
      ]
    },

    "JS Value": {
      "prefix": "va",
      "body": [
        "js.Value"
      ]
    },

    "To-do": {
      "prefix": "todo",
      "body":[
        "// TODO: $0"
      ]
    },

    "Float64": {
      "prefix": "fl",
      "body": [
        "float64($0)"
      ]
    },

    "Method": {
      "prefix": "m",
      "body": [
        "// $3 ${4:implementation}.",
        "func ($1 *$2) $3($5) $6 {",
        "  $0",
        "}"
      ]
    },

    "Method Copy": {
      "prefix": "mm",
      "body": [
        "// $3 ${4:implementation}.",
        "func ($1 $2) $3($5) $6 {",
        "  $0",
        "}"
      ]
    },

    "Method Chained": {
      "prefix": "mc",
      "body": [
        "// $3 ${4:implementation}.",
        "func ($1 *$2) $3($5) $6 {",
        "  $0",
        "  return $1",
        "}"
      ]
    },

    "Sprintf": {
      "prefix": "ss",
      "body": [
        "fmt.Sprintf(\"$1\", $0)"
      ]
    },

    "If Error": {
      "prefix": "e",
      "body": [
        "if err != nil {",
        "  $0",
        "}"
      ]
    },

    "If Error Oneliner": {
      "prefix": "ie",
      "body": [
        "if err := $1; err != nil {",
        "  $0",
        "}"
      ]
    },

    "Error Wrap": {
      "prefix": "ew",
      "body": [
        "errors.Wrap(err, \"$0\")"
      ]
    },

    "Error Wrapf": {
      "prefix": "ewf",
      "body": [
        "errors.Wrapf(err, \"$1\", $0)"
      ]
    },

    "Return": {
      "prefix": "r",
      "body": [
        "return "
      ]
    },

    "Return Error": {
      "prefix": "re",
      "body": [
        "return err"
      ]
    },

    "Return Nil": {
      "prefix": "n",
      "body": [
        "return nil"
      ]
    },

    "Time Duration": {
      "prefix": "td",
      "body": [
        "time.Duration($0)"
      ]
    },

    "Testing TB": {
      "prefix": "tb",
      "body": [
        "t testing.TB"
      ]
    },

    "Time Now": {
      "prefix": "now",
      "body": [
        "time.Now()"
      ]
    },

    "Time Start": {
      "prefix": "st",
      "body": [
        "start := time.Now()"
      ]
    },

    "Time Since": {
      "prefix": "ts",
      "body": [
        "time.Since(${0:start})"
      ]
    },

    "Assert Equal": {
      "prefix": "ae",
      "body": [
        "assert.Equal(t, ${1:expected}, ${2:actual})"
      ]
    },

    "Assert Error Equal": {
      "prefix": "aee",
      "body": [
        "assert.EqualError(t, ${1:err}, `${0:msg}`)"
      ]
    },

    "Assert No Error": {
      "prefix": "no",
      "body": [
        "assert.NoError(t, err${1:, \"$0\"})"
      ]
    },

    "Map": {
      "prefix": "ma",
      "body": [
        "map[${1:string}]${0:value}"
      ]
    },

    "HTTP Error": {
      "prefix": "he",
      "body": [
        "http.Error(w, \"$1\", http.Status$2)"
      ]
    },

    "HTTP Handler": {
      "prefix": "ha",
      "body": [
        "w http.ResponseWriter, r *http.Request"
      ]
    },

    "Hex Dump": {
      "prefix": "hd",
      "body": [
        "fmt.Printf(\"%s\\\\n\", hex.Dump($1))"
      ]
    },

    "Tag": {
      "prefix": "tag",
      "body": [
        "`$1:\"$2\"`"
      ]
    },

    "Bytes": {
      "prefix": "b",
      "body": [
        "[]byte($1)"
      ]
    },

    "Main": {
      "prefix": "main",
      "body": [
        "func main(){",
        "  $0",
        "}"
      ]
    },

    "Init": {
      "prefix": "init",
      "body": [
        "func init(){",
        "  $0",
        "}"
      ]
    },

    "Function": {
      "prefix": "f",
      "body": [
        "// $1 $2.",
        "func $1($3) $4 {",
        "  $0",
        "}"
      ]
    },

    "Function Anonymous": {
      "prefix": "ff",
      "body": [
        "func ($1) $2 {",
        "  $0",
        "}"
      ]
    },

    "Struct": {
      "prefix": "s",
      "body": [
        "// $1 $2.",
        "type $1 struct {",
        "  $0",
        "}"
      ]
    },

    "Struct Field": {
      "prefix": "sf",
      "body": [
        "// $1 $3.",
        "${1:Name} ${2:string}"
      ]
    },

    "Context Argument": {
      "prefix": "con",
      "body": [
        "ctx context.Context"
      ]
    },

    "Context Background": {
      "prefix": "cb",
      "body": [
        "context.Background()"
      ]
    },

    "Hex Dump Reader": {
      "prefix": "hdr",
      "body": [
        "{",
        "  b, err := ioutil.ReadAll($0)",
        "  if err != nil {",
        "    panic(err)",
        "  }",
        "",
        "  fmt.Printf(\"%s\\\\n\", hex.Dump(b))",
        "}"
      ]
    },

    "Interface": {
      "prefix": "i",
      "body": [
        "// $1 $2.",
        "type $1 interface {",
        "  $0",
        "}"
      ]
    },

    "Lock & Unlock": {
      "prefix": "lo",
      "body": [
        "$1.Lock()",
        "defer $1.Unlock()"
      ]
    },

    "New Constructor": {
      "prefix": "ne",
      "body": [
        "// New $2.",
        "func New($3) *$1 {",
        "  return &$1{",
        "    $0",
        "  }",
        "}"
      ]
    },

    "Inspect As JSON": {
      "prefix": "ij",
      "body": [
        "{",
        "  enc := json.NewEncoder(os.Stderr)",
        "  enc.SetIndent(\"\", \"  \")",
        "  enc.Encode($0)",
        "}"
      ],
    },

    "For Range": {
      "prefix": "fr",
      "body": [
        "for _, ${1:v} := range ${2:value} {",
        "  $0",
        "}"
      ]
    },

    "Config": {
      "prefix": "config",
      "body": [
        "// Config options.",
        "type Config struct {",
        "  $0",
        "}",
        "",
        "// $1 $2",
        "type $1 struct {",
        "  Config",
        "}",
        "",
        "// New $3 with the given config.",
        "func New(c Config) *$1 {",
        "  return &$1{",
        "    Config: c,",
        "  }",
        "}"
      ]
    },

    "Benchmark Function": {
      "prefix": "bench",
      "body": [
        "// Benchmark $2.",
        "func Benchmark$1(b *testing.B) {",
        "  for i := 0; i < b.N; i++ {",
        "    $0",
        "  }",
        "}"
      ]
    },

    "Test Function": {
      "prefix": "t",
      "body": [
        "// Test $2.",
        "func Test$1(t *testing.T) {",
        "  $0",
        "}"
      ],
    },

    "Test Case": {
      "prefix": "tr", 
      "body": [
        "t.Run(\"$1\", func(t *testing.T){",
        "  $0",
        "})"
      ]
    },

    "VDOM Attributes": {
      "prefix": "at",
      "body": [
        "vdom.Attributes{",
        "  $0",
        "}"
      ]
    }
  }
xgqfrms commented 5 years ago

examples

go.go

// paramsInput params.
type paramsInput struct {

}

// paramsOutput params.
type paramsOutput struct {

}

// string-enum .
type string-enum string

// string-enums available.
const (

)

db *sqlx.DB

if v, ok := ; ok {

}
// Option function.
type Option func(*options)

// New  with the given options.
func New(options ...Option) *options {
  var v options
  for _, o := range options {
     o(&v)
  }
  return &v
}

// Witho .
func Witho() Option {
  return func() {

  }
}

logs.WithError(err).Error("le")

logs.Info("li")

logs.WithFields(log.Fields{

})

delete(, "")

pretty.Print()

fmt.Printf("%#v\n", )

log.Printf("%v\n", )

log.Fatalf("error: %s\n", err)

 = append(, )

 // +build js

 js.Value

 // TODO:

float64()

//  implementation.
func ( *) ()  {

}

//  implementation.
func ( ) ()  {

}

//  implementation.
func ( *) ()  {

  return
}

fmt.Sprintf("", )

if err != nil {

}

if err := ; err != nil {

}

errors.Wrap(err, "")

return

return err

return nil

time.Duration()

t testing.TB

time.Now()

start := time.Now()

time.Since(start)

assert.Equal(t, expected, actual)

assert.EqualError(t, err, `msg`)

assert.NoError(t, err, "")

map[string]value

http.Error(w, "", http.Status)

w http.ResponseWriter, r *http.Request

fmt.Printf("%s\n", hex.Dump())

`:""`

[]byte()

func main(){

}

func init(){

}

//  .
func ()  {

}

//  .
type  struct {

}

func ()  {

}
// Name .
Name string

ctx context.Context

context.Background()

{
  b, err := ioutil.ReadAll()
  if err != nil {
    panic(err)
  }

  fmt.Printf("%s\n", hex.Dump(b))
}

//  .
type  interface {

}

.Lock()
defer .Unlock()

// New .
func New() * {
  return &{

  }
}

{
  enc := json.NewEncoder(os.Stderr)
  enc.SetIndent("", "  ")
  enc.Encode()
}

for _, v := range value {

}

// Config options.
type Config struct {

}

//
type  struct {
  Config
}

// New  with the given config.
func New(c Config) * {
  return &{
    Config: c,
  }
}

// Benchmark .
func Benchmark(b *testing.B) {
  for i := 0; i < b.N; i++ {

  }
}

// Test .
func Test(t *testing.T) {

}

t.Run("", func(t *testing.T){

})

vdom.Attributes{

}
xgqfrms commented 5 years ago

https://github.com/tj/vscode-snippets/issues