Skip to content

Instantly share code, notes, and snippets.

@wader
Last active January 18, 2021 14:01
Show Gist options
  • Save wader/34773c1f07972bf1306315fa5b9d5f6b to your computer and use it in GitHub Desktop.
Save wader/34773c1f07972bf1306315fa5b9d5f6b to your computer and use it in GitHub Desktop.
golang get "file.go:func:line" vs code snippet
package main
import (
"fmt"
"path/filepath"
"runtime"
)
func FFL() string {
pc, f, l, _ := runtime.Caller(1)
return fmt.Sprintf("%s:%s:%d", filepath.Base(f), runtime.FuncForPC(pc).Name(), l)
}
func main() {
print(FFL())
}
{
"ffl": {
"description": "returns \"file:function:line\" of caller",
"prefix": "ffl",
"body": "func ffl() string {\n\tp, f, l, _ := runtime.Caller(1)\n\treturn fmt.Sprintf(\"%s:%s:%d\", filepath.Base(f), runtime.FuncForPC(p).Name(), l)\n}"
},
"ffl log variable content": {
"prefix": "pv",
"body": "fmt.Fprintf(os.Stderr, \"%s: ${1:var}: %#+v\\\\n\", ffl(), ${1:var})",
"description": "Snippet for log.Printf() with variable content"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment