Created
August 27, 2018 16:57
-
-
Save tsavola/b2ebecd67d927104e970998a3392bfb5 to your computer and use it in GitHub Desktop.
TODO() which prints the source code location
This file contains 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
//go:noinline | |
func TODO(...interface{}) { | |
_todo() | |
// panic("TODO") | |
} | |
//go:noinline | |
func _todo() { | |
funcName := "<unknown function>" | |
fileName := "<unknown file>" | |
fileLine := 0 | |
pc := make([]uintptr, 1) | |
n := runtime.Callers(3, pc) | |
if n > 0 { | |
f, _ := runtime.CallersFrames(pc[:n]).Next() | |
funcName = f.Function | |
fileName = f.File | |
fileLine = f.Line | |
} | |
if i := strings.LastIndex(fileName, "/"); i >= 0 { | |
fileName = fileName[i+1:] | |
} | |
if i := strings.LastIndex(funcName, "."); i >= 0 { | |
funcName = funcName[i+1:] | |
} | |
debug.Printf("TODO in %s (%s:%d)", funcName, fileName, fileLine) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment