Last active
January 18, 2021 14:01
-
-
Save wader/34773c1f07972bf1306315fa5b9d5f6b to your computer and use it in GitHub Desktop.
golang get "file.go:func:line" vs code snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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