Created
November 7, 2014 17:51
-
-
Save adamhjk/5a475b8dd45971a4e814 to your computer and use it in GitHub Desktop.
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
func dot_git_dir(dir string) string { | |
git_dir := path.Join(dir, ".git") | |
_, dir_error := os.Stat(git_dir) | |
if dir_error != nil { | |
if git_dir == "/.git" { | |
log.Fatal("Cannot find a .git directory") | |
} | |
return dot_git_dir(path.Dir(dir)) | |
} else { | |
return git_dir | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Idiomatic golang uses the early return pattern, which means you can eliminate the else part of your code. See:
https://golang.org/doc/effective_go.html#if