I am writing a utility function for my unit tests which is used by unit tests in multiple packages. This utility function must read a particular file (always the same file). Her
You can also use my method without C:
package mypackage import ( "path/filepath" "runtime" "fmt" ) var ( _, b, _, _ = runtime.Caller(0) basepath = filepath.Dir(b) ) func PrintMyPath() { fmt.Println(basepath) }
https://play.golang.org/p/ifVRIq7Tx0