Skip to content

Commit

Permalink
Add debug snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhao-pro committed Oct 20, 2022
1 parent 2a394ef commit 48aea49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions UltiSnips/go.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func main() {
endsnippet

snippet /^meth/ "Method" r
// $3 ...
func (${1:receiver} ${2:type}) ${3:name}(${4:params})${5/(.+)/ /}${5:type} {
${0:${VISUAL}}
}
Expand Down
10 changes: 9 additions & 1 deletion snippets/go.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,19 @@ snippet errwr "Error handling with errors.Wrap"
return errors.Wrap(err, "${2}")
}

snippet dp "print debug info"
func (){
// DEBUG: remove before commit
_, file, line, _ := runtime.Caller(0)
fmt.Println(file, line, ${1})
}()

snippet jp "json Marshal and print"
func (name string){
// DEBUG: remove before commit
_, file, line, _ := runtime.Caller(0)
jb, _ := json.MarshalIndent(${1}, "", " ")
fmt.Printf("\n[%s]\n%s\n\n", name, string(jb))
fmt.Printf("\n[%s:%s - %s]\n%s\n\n", file, line, name, string(jb))
_ = ioutil.WriteFile(name + ".json", jb, 0644)
}("${2}")

Expand Down

0 comments on commit 48aea49

Please sign in to comment.