go-root-dir/root_dir.go

21 lines
366 B
Go

package root_dir
import (
"os"
"regexp"
)
func RootDir(projectDirName string) string {
if projectDirName == "" {
return ""
}
projectName := regexp.MustCompile(`^(.*` + projectDirName + `)`)
currentWorkDirectory, _ := os.Getwd()
rootPath := projectName.Find([]byte(currentWorkDirectory))
if len(rootPath) <= 0 {
return ""
}
return string(rootPath)
}