util.go
func resolveDir(path string) (string, string, string) {
	dir := path
	for dir != "" && dir != "/" && dir != "." {
		port := ""
		i, j := strings.LastIndex(dir, ":"), strings.LastIndex(dir, "/")
		if i != -1 && i > j {
			port = dir[i+1:]
			dir = dir[:i]
		}

		if mode(dir)&os.ModeDir != 0 {
			rest := strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(path, dir), ":"+port), "/")
			return dir, port, rest
		}

		if j != -1 {
			dir = dir[:j]
		} else {
			dir = ""
		}
	}

	return path, "", ""
}
func resolveDir(path string) (string, string, string) {
	dir := path
	for dir != "" && dir != "/" && dir != "." {
		port := ""
		i, j := strings.LastIndex(dir, ":"), strings.LastIndex(dir, "/")
		if i != -1 && i > j {
			port = dir[i+1:]
			dir = dir[:i]
		}

		if mode(dir)&os.ModeDir != 0 {
			rest := strings.TrimPrefix(strings.TrimPrefix(strings.TrimPrefix(path, dir), ":"+port), "/")
			return dir, port, rest
		}

		if j != -1 {
			dir = dir[:j]
		} else {
			dir = ""
		}
	}

	return path, "", ""
}
// resolveDir resolves a directory with a :port list.
//
// Used for PostgreSQL DSNs.