Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created July 11, 2010 07:54
Show Gist options
  • Save alloy-d/471381 to your computer and use it in GitHub Desktop.
Save alloy-d/471381 to your computer and use it in GitHub Desktop.
Finding the directory a file resides in in Go -- please tell me I'm doin' it wrong.
// I feel like this can't possibly be how you're *supposed*
// to find the directory a file resides in in Go.
package clever
import (
"path"
"runtime"
)
func GetMyDir() string {
_, file, _, _ := runtime.Caller(0)
dir, _ := path.Split(file)
return dir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment