Created
June 3, 2016 23:05
-
-
Save hibooboo2/3679224f53e168c2bbda4b5517fab342 to your computer and use it in GitHub Desktop.
Gist to make and return an error that you can use to represent a go function that is not yet implemented based on where the function is called from.
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
package dev | |
import ( | |
"fmt" | |
"log" | |
"runtime" | |
"strings" | |
) | |
func notImplemented() error { | |
pc := make([]uintptr, 10) // at least 1 entry needed | |
runtime.Callers(2, pc) | |
f := runtime.FuncForPC(pc[0]) | |
file, line := f.FileLine(pc[0]) | |
index := strings.LastIndex(file, "/") + 1 | |
if len(file) >= index { | |
file = file[index:] | |
} | |
funcName := f.Name() | |
funcName = funcName[strings.Index(funcName, ".")+1:] | |
err := fmt.Errorf("Implement: %v:%v @%v\n", file, line, funcName) | |
log.Println(err.Error()) | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add this function and call it you get an error something like this:
Implement: utils.go:249 @verifyName
Where utils.go is the file and verifyName is the name of the function that is not yet implemented.