package filepathext import ( "path/filepath" "runtime" "strings" ) // SmartJoin joins two paths, treating the second path as absolute if it is an // absolute path. func SmartJoin(one, two string) string { if SmartIsAbs(two) { return two } return filepath.Join(one, two) } // SmartIsAbs checks if a path is absolute, considering both OS-specific and // Unix-style paths. func SmartIsAbs(path string) bool { switch runtime.GOOS { case "windows": return filepath.IsAbs(path) || strings.HasPrefix(filepath.ToSlash(path), "/") default: return filepath.IsAbs(path) } }