Skip to content

Instantly share code, notes, and snippets.

@hibooboo2
Created June 3, 2016 23:05
Show Gist options
  • Save hibooboo2/3679224f53e168c2bbda4b5517fab342 to your computer and use it in GitHub Desktop.
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.
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
}
@hibooboo2
Copy link
Author

hibooboo2 commented Jun 3, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment